gd_tokenizer.cpp 31 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421
  1. /*************************************************************************/
  2. /* gd_tokenizer.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* http://www.godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
  9. /* */
  10. /* Permission is hereby granted, free of charge, to any person obtaining */
  11. /* a copy of this software and associated documentation files (the */
  12. /* "Software"), to deal in the Software without restriction, including */
  13. /* without limitation the rights to use, copy, modify, merge, publish, */
  14. /* distribute, sublicense, and/or sell copies of the Software, and to */
  15. /* permit persons to whom the Software is furnished to do so, subject to */
  16. /* the following conditions: */
  17. /* */
  18. /* The above copyright notice and this permission notice shall be */
  19. /* included in all copies or substantial portions of the Software. */
  20. /* */
  21. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  22. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  23. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  24. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  25. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  26. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  27. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  28. /*************************************************************************/
  29. #include "gd_tokenizer.h"
  30. #include "print_string.h"
  31. #include "gd_functions.h"
  32. #include "io/marshalls.h"
  33. #include "map.h"
  34. const char* GDTokenizer::token_names[TK_MAX]={
  35. "Empty",
  36. "Identifier",
  37. "Constant",
  38. "Self",
  39. "Built-In Type",
  40. "Built-In Func",
  41. "In",
  42. "'=='",
  43. "'!='",
  44. "'<'",
  45. "'<='",
  46. "'>'",
  47. "'>='",
  48. "'and'",
  49. "'or'",
  50. "'not'",
  51. "'+'",
  52. "'-'",
  53. "'*'",
  54. "'/'",
  55. "'%'",
  56. "'<<'",
  57. "'>>'",
  58. "'='",
  59. "'+='",
  60. "'-='",
  61. "'*='",
  62. "'/='",
  63. "'%='",
  64. "'<<='",
  65. "'>>='",
  66. "'&='",
  67. "'|='",
  68. "'^='",
  69. "'&'",
  70. "'|'",
  71. "'^'",
  72. "'~'",
  73. //"Plus Plus",
  74. //"Minus Minus",
  75. "if",
  76. "elif",
  77. "else",
  78. "for",
  79. "do",
  80. "while",
  81. "switch (reserved)",
  82. "case (reserved)",
  83. "break",
  84. "continue",
  85. "pass",
  86. "return",
  87. "match",
  88. "func",
  89. "class",
  90. "extends",
  91. "onready",
  92. "tool",
  93. "static",
  94. "export",
  95. "setget",
  96. "const",
  97. "var",
  98. "enum",
  99. "preload",
  100. "assert",
  101. "yield",
  102. "signal",
  103. "breakpoint",
  104. "rpc",
  105. "sync",
  106. "master",
  107. "slave",
  108. "'['",
  109. "']'",
  110. "'{'",
  111. "'}'",
  112. "'('",
  113. "')'",
  114. "','",
  115. "';'",
  116. "'.'",
  117. "'?'",
  118. "':'",
  119. "'\\n'",
  120. "PI",
  121. "Error",
  122. "EOF",
  123. "Cursor"};
  124. const char *GDTokenizer::get_token_name(Token p_token) {
  125. ERR_FAIL_INDEX_V(p_token,TK_MAX,"<error>");
  126. return token_names[p_token];
  127. }
  128. static bool _is_text_char(CharType c) {
  129. return (c>='a' && c<='z') || (c>='A' && c<='Z') || (c>='0' && c<='9') || c=='_';
  130. }
  131. static bool _is_number(CharType c) {
  132. return (c>='0' && c<='9');
  133. }
  134. static bool _is_hex(CharType c) {
  135. return (c>='0' && c<='9') || (c>='a' && c<='f') || (c>='A' && c<='F');
  136. }
  137. void GDTokenizerText::_make_token(Token p_type) {
  138. TokenData &tk=tk_rb[tk_rb_pos];
  139. tk.type=p_type;
  140. tk.line=line;
  141. tk.col=column;
  142. tk_rb_pos=(tk_rb_pos+1)%TK_RB_SIZE;
  143. }
  144. void GDTokenizerText::_make_identifier(const StringName& p_identifier) {
  145. TokenData &tk=tk_rb[tk_rb_pos];
  146. tk.type=TK_IDENTIFIER;
  147. tk.identifier=p_identifier;
  148. tk.line=line;
  149. tk.col=column;
  150. tk_rb_pos=(tk_rb_pos+1)%TK_RB_SIZE;
  151. }
  152. void GDTokenizerText::_make_built_in_func(GDFunctions::Function p_func) {
  153. TokenData &tk=tk_rb[tk_rb_pos];
  154. tk.type=TK_BUILT_IN_FUNC;
  155. tk.func=p_func;
  156. tk.line=line;
  157. tk.col=column;
  158. tk_rb_pos=(tk_rb_pos+1)%TK_RB_SIZE;
  159. }
  160. void GDTokenizerText::_make_constant(const Variant& p_constant) {
  161. TokenData &tk=tk_rb[tk_rb_pos];
  162. tk.type=TK_CONSTANT;
  163. tk.constant=p_constant;
  164. tk.line=line;
  165. tk.col=column;
  166. tk_rb_pos=(tk_rb_pos+1)%TK_RB_SIZE;
  167. }
  168. void GDTokenizerText::_make_type(const Variant::Type& p_type) {
  169. TokenData &tk=tk_rb[tk_rb_pos];
  170. tk.type=TK_BUILT_IN_TYPE;
  171. tk.vtype=p_type;
  172. tk.line=line;
  173. tk.col=column;
  174. tk_rb_pos=(tk_rb_pos+1)%TK_RB_SIZE;
  175. }
  176. void GDTokenizerText::_make_error(const String& p_error) {
  177. error_flag=true;
  178. last_error=p_error;
  179. TokenData &tk=tk_rb[tk_rb_pos];
  180. tk.type=TK_ERROR;
  181. tk.constant=p_error;
  182. tk.line=line;
  183. tk.col=column;
  184. tk_rb_pos=(tk_rb_pos+1)%TK_RB_SIZE;
  185. }
  186. void GDTokenizerText::_make_newline(int p_spaces) {
  187. TokenData &tk=tk_rb[tk_rb_pos];
  188. tk.type=TK_NEWLINE;
  189. tk.constant=p_spaces;
  190. tk.line=line;
  191. tk.col=column;
  192. tk_rb_pos=(tk_rb_pos+1)%TK_RB_SIZE;
  193. }
  194. void GDTokenizerText::_advance() {
  195. if (error_flag) {
  196. //parser broke
  197. _make_error(last_error);
  198. return;
  199. }
  200. if (code_pos>=len) {
  201. _make_token(TK_EOF);
  202. return;
  203. }
  204. #define GETCHAR(m_ofs) ((m_ofs+code_pos)>=len?0:_code[m_ofs+code_pos])
  205. #define INCPOS(m_amount) { code_pos+=m_amount; column+=m_amount; }
  206. while (true) {
  207. bool is_node_path = false;
  208. StringMode string_mode=STRING_DOUBLE_QUOTE;
  209. switch(GETCHAR(0)) {
  210. case 0:
  211. _make_token(TK_EOF);
  212. break;
  213. case '\\':
  214. INCPOS(1);
  215. if (GETCHAR(0)=='\r') {
  216. INCPOS(1);
  217. }
  218. if (GETCHAR(0)!='\n') {
  219. _make_error("Expected newline after '\\'.");
  220. return;
  221. }
  222. INCPOS(1);
  223. line++;
  224. while(GETCHAR(0)==' ' || GETCHAR(0)=='\t') {
  225. INCPOS(1);
  226. }
  227. continue;
  228. case '\t':
  229. case '\r':
  230. case ' ':
  231. INCPOS(1);
  232. continue;
  233. case '\n': {
  234. line++;
  235. INCPOS(1);
  236. column=1;
  237. int i=0;
  238. while(GETCHAR(i)==' ' || GETCHAR(i)=='\t') {
  239. i++;
  240. }
  241. _make_newline(i);
  242. return;
  243. }
  244. #if 1 //py style tokenizer
  245. case '#': { // line comment skip
  246. while(GETCHAR(0)!='\n') {
  247. code_pos++;
  248. if (GETCHAR(0)==0) { //end of file
  249. //_make_error("Unterminated Comment");
  250. _make_token(TK_EOF);
  251. return;
  252. }
  253. }
  254. INCPOS(1);
  255. column=1;
  256. line++;
  257. int i=0;
  258. while(GETCHAR(i)==' ' || GETCHAR(i)=='\t') {
  259. i++;
  260. }
  261. _make_newline(i);
  262. return;
  263. } break;
  264. #endif
  265. case '/': {
  266. switch(GETCHAR(1)) {
  267. #if 0 // c style tokenizer
  268. case '*': { // block comment
  269. int pos = code_pos+2;
  270. int new_line=line;
  271. int new_col=column+2;
  272. while(true) {
  273. if (_code[pos]=='0') {
  274. _make_error("Unterminated Comment");
  275. code_pos=pos;
  276. return;
  277. }
  278. if (_code[pos]=='*' && _code[pos+1]=='/') {
  279. new_col+=2;
  280. pos+=2; //compensate
  281. break;
  282. } else if (_code[pos]=='\n') {
  283. new_line++;
  284. new_col=1;
  285. } else {
  286. new_col++;
  287. }
  288. pos++;
  289. }
  290. column=new_col;
  291. line=new_line;
  292. code_pos=pos;
  293. continue;
  294. } break;
  295. case '/': { // line comment skip
  296. while(GETCHAR(0)!='\n') {
  297. code_pos++;
  298. if (GETCHAR(0)==0) { //end of file
  299. _make_error("Unterminated Comment");
  300. return;
  301. }
  302. }
  303. INCPOS(1);
  304. column=1;
  305. line++;
  306. continue;
  307. } break;
  308. #endif
  309. case '=': { // diveq
  310. _make_token(TK_OP_ASSIGN_DIV);
  311. INCPOS(1);
  312. } break;
  313. default:
  314. _make_token(TK_OP_DIV);
  315. }
  316. } break;
  317. case '=': {
  318. if (GETCHAR(1)=='=') {
  319. _make_token(TK_OP_EQUAL);
  320. INCPOS(1);
  321. } else
  322. _make_token(TK_OP_ASSIGN);
  323. } break;
  324. case '<': {
  325. if (GETCHAR(1)=='=') {
  326. _make_token(TK_OP_LESS_EQUAL);
  327. INCPOS(1);
  328. } else if (GETCHAR(1)=='<') {
  329. if (GETCHAR(2)=='=') {
  330. _make_token(TK_OP_ASSIGN_SHIFT_LEFT);
  331. INCPOS(1);
  332. } else {
  333. _make_token(TK_OP_SHIFT_LEFT);
  334. }
  335. INCPOS(1);
  336. } else
  337. _make_token(TK_OP_LESS);
  338. } break;
  339. case '>': {
  340. if (GETCHAR(1)=='=') {
  341. _make_token(TK_OP_GREATER_EQUAL);
  342. INCPOS(1);
  343. } else if (GETCHAR(1)=='>') {
  344. if (GETCHAR(2)=='=') {
  345. _make_token(TK_OP_ASSIGN_SHIFT_RIGHT);
  346. INCPOS(1);
  347. } else {
  348. _make_token(TK_OP_SHIFT_RIGHT);
  349. }
  350. INCPOS(1);
  351. } else {
  352. _make_token(TK_OP_GREATER);
  353. }
  354. } break;
  355. case '!': {
  356. if (GETCHAR(1)=='=') {
  357. _make_token(TK_OP_NOT_EQUAL);
  358. INCPOS(1);
  359. } else {
  360. _make_token(TK_OP_NOT);
  361. }
  362. } break;
  363. //case '"' //string - no strings in shader
  364. //case '\'' //string - no strings in shader
  365. case '{':
  366. _make_token(TK_CURLY_BRACKET_OPEN);
  367. break;
  368. case '}':
  369. _make_token(TK_CURLY_BRACKET_CLOSE);
  370. break;
  371. case '[':
  372. _make_token(TK_BRACKET_OPEN);
  373. break;
  374. case ']':
  375. _make_token(TK_BRACKET_CLOSE);
  376. break;
  377. case '(':
  378. _make_token(TK_PARENTHESIS_OPEN);
  379. break;
  380. case ')':
  381. _make_token(TK_PARENTHESIS_CLOSE);
  382. break;
  383. case ',':
  384. _make_token(TK_COMMA);
  385. break;
  386. case ';':
  387. _make_token(TK_SEMICOLON);
  388. break;
  389. case '?':
  390. _make_token(TK_QUESTION_MARK);
  391. break;
  392. case ':':
  393. _make_token(TK_COLON); //for methods maybe but now useless.
  394. break;
  395. case '$':
  396. _make_token(TK_DOLLAR); //for the get_node() shortener
  397. break;
  398. case '^': {
  399. if (GETCHAR(1)=='=') {
  400. _make_token(TK_OP_ASSIGN_BIT_XOR);
  401. INCPOS(1);
  402. } else {
  403. _make_token(TK_OP_BIT_XOR);
  404. }
  405. } break;
  406. case '~':
  407. _make_token(TK_OP_BIT_INVERT);
  408. break;
  409. case '&': {
  410. if (GETCHAR(1)=='&') {
  411. _make_token(TK_OP_AND);
  412. INCPOS(1);
  413. } else if (GETCHAR(1)=='=') {
  414. _make_token(TK_OP_ASSIGN_BIT_AND);
  415. INCPOS(1);
  416. } else {
  417. _make_token(TK_OP_BIT_AND);
  418. }
  419. } break;
  420. case '|': {
  421. if (GETCHAR(1)=='|') {
  422. _make_token(TK_OP_OR);
  423. INCPOS(1);
  424. } else if (GETCHAR(1)=='=') {
  425. _make_token(TK_OP_ASSIGN_BIT_OR);
  426. INCPOS(1);
  427. } else {
  428. _make_token(TK_OP_BIT_OR);
  429. }
  430. } break;
  431. case '*': {
  432. if (GETCHAR(1)=='=') {
  433. _make_token(TK_OP_ASSIGN_MUL);
  434. INCPOS(1);
  435. } else {
  436. _make_token(TK_OP_MUL);
  437. }
  438. } break;
  439. case '+': {
  440. if (GETCHAR(1)=='=') {
  441. _make_token(TK_OP_ASSIGN_ADD);
  442. INCPOS(1);
  443. /*
  444. } else if (GETCHAR(1)=='+') {
  445. _make_token(TK_OP_PLUS_PLUS);
  446. INCPOS(1);
  447. */
  448. } else {
  449. _make_token(TK_OP_ADD);
  450. }
  451. } break;
  452. case '-': {
  453. if (GETCHAR(1)=='=') {
  454. _make_token(TK_OP_ASSIGN_SUB);
  455. INCPOS(1);
  456. /*
  457. } else if (GETCHAR(1)=='-') {
  458. _make_token(TK_OP_MINUS_MINUS);
  459. INCPOS(1);
  460. */
  461. } else {
  462. _make_token(TK_OP_SUB);
  463. }
  464. } break;
  465. case '%': {
  466. if (GETCHAR(1)=='=') {
  467. _make_token(TK_OP_ASSIGN_MOD);
  468. INCPOS(1);
  469. } else {
  470. _make_token(TK_OP_MOD);
  471. }
  472. } break;
  473. case '@':
  474. if( CharType(GETCHAR(1))!='"' && CharType(GETCHAR(1))!='\'' ) {
  475. _make_error("Unexpected '@'");
  476. return;
  477. }
  478. INCPOS(1);
  479. is_node_path=true;
  480. case '\'':
  481. case '"': {
  482. if (GETCHAR(0)=='\'')
  483. string_mode=STRING_SINGLE_QUOTE;
  484. int i=1;
  485. if (string_mode==STRING_DOUBLE_QUOTE && GETCHAR(i)=='"' && GETCHAR(i+1)=='"') {
  486. i+=2;
  487. string_mode=STRING_MULTILINE;
  488. }
  489. String str;
  490. while(true) {
  491. if (CharType(GETCHAR(i))==0) {
  492. _make_error("Unterminated String");
  493. return;
  494. } else if( string_mode==STRING_DOUBLE_QUOTE && CharType(GETCHAR(i))=='"' ) {
  495. break;
  496. } else if( string_mode==STRING_SINGLE_QUOTE && CharType(GETCHAR(i))=='\'' ) {
  497. break;
  498. } else if( string_mode==STRING_MULTILINE && CharType(GETCHAR(i))=='\"' && CharType(GETCHAR(i+1))=='\"' && CharType(GETCHAR(i+2))=='\"') {
  499. i+=2;
  500. break;
  501. } else if( string_mode!=STRING_MULTILINE && CharType(GETCHAR(i))=='\n') {
  502. _make_error("Unexpected EOL at String.");
  503. return;
  504. } else if( CharType(GETCHAR(i))==0xFFFF) {
  505. //string ends here, next will be TK
  506. i--;
  507. break;
  508. } else if (CharType(GETCHAR(i))=='\\') {
  509. //escaped characters...
  510. i++;
  511. CharType next = GETCHAR(i);
  512. if (next==0) {
  513. _make_error("Unterminated String");
  514. return;
  515. }
  516. CharType res=0;
  517. switch(next) {
  518. case 'a': res=7; break;
  519. case 'b': res=8; break;
  520. case 't': res=9; break;
  521. case 'n': res=10; break;
  522. case 'v': res=11; break;
  523. case 'f': res=12; break;
  524. case 'r': res=13; break;
  525. case '\'': res='\''; break;
  526. case '\"': res='\"'; break;
  527. case '\\': res='\\'; break;
  528. case '/': res='/'; break; //wtf
  529. case 'u': {
  530. //hexnumbarh - oct is deprecated
  531. i+=1;
  532. for(int j=0;j<4;j++) {
  533. CharType c = GETCHAR(i+j);
  534. if (c==0) {
  535. _make_error("Unterminated String");
  536. return;
  537. }
  538. if (!((c>='0' && c<='9') || (c>='a' && c<='f') || (c>='A' && c<='F'))) {
  539. _make_error("Malformed hex constant in string");
  540. return;
  541. }
  542. CharType v;
  543. if (c>='0' && c<='9') {
  544. v=c-'0';
  545. } else if (c>='a' && c<='f') {
  546. v=c-'a';
  547. v+=10;
  548. } else if (c>='A' && c<='F') {
  549. v=c-'A';
  550. v+=10;
  551. } else {
  552. ERR_PRINT("BUG");
  553. v=0;
  554. }
  555. res<<=4;
  556. res|=v;
  557. }
  558. i+=3;
  559. } break;
  560. default: {
  561. _make_error("Invalid escape sequence");
  562. return;
  563. } break;
  564. }
  565. str+=res;
  566. } else {
  567. if (CharType(GETCHAR(i))=='\n') {
  568. line++;
  569. column=1;
  570. }
  571. str+=CharType(GETCHAR(i));
  572. }
  573. i++;
  574. }
  575. INCPOS(i);
  576. if (is_node_path) {
  577. _make_constant(NodePath(str));
  578. } else {
  579. _make_constant(str);
  580. }
  581. } break;
  582. case 0xFFFF: {
  583. _make_token(TK_CURSOR);
  584. } break;
  585. default: {
  586. if (_is_number(GETCHAR(0)) || (GETCHAR(0)=='.' && _is_number(GETCHAR(1)))) {
  587. // parse number
  588. bool period_found=false;
  589. bool exponent_found=false;
  590. bool hexa_found=false;
  591. bool sign_found=false;
  592. String str;
  593. int i=0;
  594. while(true) {
  595. if (GETCHAR(i)=='.') {
  596. if (period_found || exponent_found) {
  597. _make_error("Invalid numeric constant at '.'");
  598. return;
  599. }
  600. period_found=true;
  601. } else if (GETCHAR(i)=='x') {
  602. if (hexa_found || str.length()!=1 || !( (i==1 && str[0]=='0') || (i==2 && str[1]=='0' && str[0]=='-') ) ) {
  603. _make_error("Invalid numeric constant at 'x'");
  604. return;
  605. }
  606. hexa_found=true;
  607. } else if (!hexa_found && GETCHAR(i)=='e') {
  608. if (hexa_found || exponent_found) {
  609. _make_error("Invalid numeric constant at 'e'");
  610. return;
  611. }
  612. exponent_found=true;
  613. } else if (_is_number(GETCHAR(i))) {
  614. //all ok
  615. } else if (hexa_found && _is_hex(GETCHAR(i))) {
  616. } else if ((GETCHAR(i)=='-' || GETCHAR(i)=='+') && exponent_found) {
  617. if (sign_found) {
  618. _make_error("Invalid numeric constant at '-'");
  619. return;
  620. }
  621. sign_found=true;
  622. } else
  623. break;
  624. str+=CharType(GETCHAR(i));
  625. i++;
  626. }
  627. if (!( _is_number(str[str.length()-1]) || (hexa_found && _is_hex(str[str.length()-1])))) {
  628. _make_error("Invalid numeric constant: "+str);
  629. return;
  630. }
  631. INCPOS(str.length());
  632. if (hexa_found) {
  633. int64_t val = str.hex_to_int64();
  634. _make_constant(val);
  635. } else if (period_found || exponent_found) {
  636. double val = str.to_double();
  637. //print_line("*%*%*%*% to convert: "+str+" result: "+rtos(val));
  638. _make_constant(val);
  639. } else {
  640. int64_t val = str.to_int64();
  641. _make_constant(val);
  642. }
  643. return;
  644. }
  645. if (GETCHAR(0)=='.') {
  646. //parse period
  647. _make_token(TK_PERIOD);
  648. break;
  649. }
  650. if (_is_text_char(GETCHAR(0))) {
  651. // parse identifier
  652. String str;
  653. str+=CharType(GETCHAR(0));
  654. int i=1;
  655. while(_is_text_char(GETCHAR(i))) {
  656. str+=CharType(GETCHAR(i));
  657. i++;
  658. }
  659. bool identifier=false;
  660. if (str=="null") {
  661. _make_constant(Variant());
  662. } else if (str=="true") {
  663. _make_constant(true);
  664. } else if (str=="false") {
  665. _make_constant(false);
  666. } else {
  667. bool found=false;
  668. struct _bit { Variant::Type type; const char *text;};
  669. //built in types
  670. static const _bit type_list[]={
  671. //types
  672. {Variant::BOOL,"bool"},
  673. {Variant::INT,"int"},
  674. {Variant::REAL,"float"},
  675. {Variant::STRING,"String"},
  676. {Variant::VECTOR2,"Vector2"},
  677. {Variant::RECT2,"Rect2"},
  678. {Variant::TRANSFORM2D,"Transform2D"},
  679. {Variant::VECTOR3,"Vector3"},
  680. {Variant::RECT3,"Rect3"},
  681. {Variant::PLANE,"Plane"},
  682. {Variant::QUAT,"Quat"},
  683. {Variant::BASIS,"Basis"},
  684. {Variant::TRANSFORM,"Transform"},
  685. {Variant::COLOR,"Color"},
  686. {Variant::IMAGE,"Image"},
  687. {Variant::_RID,"RID"},
  688. {Variant::OBJECT,"Object"},
  689. {Variant::INPUT_EVENT,"InputEvent"},
  690. {Variant::NODE_PATH,"NodePath"},
  691. {Variant::DICTIONARY,"Dictionary"},
  692. {Variant::ARRAY,"Array"},
  693. {Variant::POOL_BYTE_ARRAY,"PoolByteArray"},
  694. {Variant::POOL_INT_ARRAY,"PoolIntArray"},
  695. {Variant::POOL_REAL_ARRAY,"PoolFloatArray"},
  696. {Variant::POOL_STRING_ARRAY,"PoolStringArray"},
  697. {Variant::POOL_VECTOR2_ARRAY,"PoolVector2Array"},
  698. {Variant::POOL_VECTOR3_ARRAY,"PoolVector3Array"},
  699. {Variant::POOL_COLOR_ARRAY,"PoolColorArray"},
  700. {Variant::VARIANT_MAX,NULL},
  701. };
  702. {
  703. int idx=0;
  704. while(type_list[idx].text) {
  705. if (str==type_list[idx].text) {
  706. _make_type(type_list[idx].type);
  707. found=true;
  708. break;
  709. }
  710. idx++;
  711. }
  712. }
  713. if (!found) {
  714. //built in func?
  715. for(int i=0;i<GDFunctions::FUNC_MAX;i++) {
  716. if (str==GDFunctions::get_func_name(GDFunctions::Function(i))) {
  717. _make_built_in_func(GDFunctions::Function(i));
  718. found=true;
  719. break;
  720. }
  721. }
  722. //keywor
  723. }
  724. if (!found) {
  725. struct _kws { Token token; const char *text;};
  726. static const _kws keyword_list[]={
  727. //ops
  728. {TK_OP_IN,"in"},
  729. {TK_OP_NOT,"not"},
  730. {TK_OP_OR,"or"},
  731. {TK_OP_AND,"and"},
  732. //func
  733. {TK_PR_FUNCTION,"func"},
  734. {TK_PR_CLASS,"class"},
  735. {TK_PR_EXTENDS,"extends"},
  736. {TK_PR_ONREADY,"onready"},
  737. {TK_PR_TOOL,"tool"},
  738. {TK_PR_STATIC,"static"},
  739. {TK_PR_EXPORT,"export"},
  740. {TK_PR_SETGET,"setget"},
  741. {TK_PR_VAR,"var"},
  742. {TK_PR_PRELOAD,"preload"},
  743. {TK_PR_ASSERT,"assert"},
  744. {TK_PR_YIELD,"yield"},
  745. {TK_PR_SIGNAL,"signal"},
  746. {TK_PR_BREAKPOINT,"breakpoint"},
  747. {TK_PR_REMOTE,"remote"},
  748. {TK_PR_MASTER,"master"},
  749. {TK_PR_SLAVE,"slave"},
  750. {TK_PR_SYNC,"sync"},
  751. {TK_PR_CONST,"const"},
  752. {TK_PR_ENUM,"enum"},
  753. //controlflow
  754. {TK_CF_IF,"if"},
  755. {TK_CF_ELIF,"elif"},
  756. {TK_CF_ELSE,"else"},
  757. {TK_CF_FOR,"for"},
  758. {TK_CF_WHILE,"while"},
  759. {TK_CF_DO,"do"},
  760. {TK_CF_SWITCH,"switch"},
  761. {TK_CF_CASE,"case"},
  762. {TK_CF_BREAK,"break"},
  763. {TK_CF_CONTINUE,"continue"},
  764. {TK_CF_RETURN,"return"},
  765. {TK_CF_MATCH, "match"},
  766. {TK_CF_PASS,"pass"},
  767. {TK_SELF,"self"},
  768. {TK_CONST_PI,"PI"},
  769. {TK_ERROR,NULL}
  770. };
  771. int idx=0;
  772. found=false;
  773. while(keyword_list[idx].text) {
  774. if (str==keyword_list[idx].text) {
  775. _make_token(keyword_list[idx].token);
  776. found=true;
  777. break;
  778. }
  779. idx++;
  780. }
  781. }
  782. if (!found)
  783. identifier=true;
  784. }
  785. if (identifier) {
  786. _make_identifier(str);
  787. }
  788. INCPOS(str.length());
  789. return;
  790. }
  791. _make_error("Unknown character");
  792. return;
  793. } break;
  794. }
  795. INCPOS(1);
  796. break;
  797. }
  798. }
  799. void GDTokenizerText::set_code(const String& p_code) {
  800. code=p_code;
  801. len = p_code.length();
  802. if (len) {
  803. _code=&code[0];
  804. } else {
  805. _code=NULL;
  806. }
  807. code_pos=0;
  808. line=1; //it is stand-ar-ized that lines begin in 1 in code..
  809. column=1; //the same holds for columns
  810. tk_rb_pos=0;
  811. error_flag=false;
  812. last_error="";
  813. for(int i=0;i<MAX_LOOKAHEAD+1;i++)
  814. _advance();
  815. }
  816. GDTokenizerText::Token GDTokenizerText::get_token(int p_offset) const {
  817. ERR_FAIL_COND_V( p_offset <= -MAX_LOOKAHEAD, TK_ERROR);
  818. ERR_FAIL_COND_V( p_offset >= MAX_LOOKAHEAD, TK_ERROR);
  819. int ofs = (TK_RB_SIZE + tk_rb_pos + p_offset - MAX_LOOKAHEAD -1)%TK_RB_SIZE;
  820. return tk_rb[ofs].type;
  821. }
  822. int GDTokenizerText::get_token_line(int p_offset) const {
  823. ERR_FAIL_COND_V( p_offset <= -MAX_LOOKAHEAD, -1);
  824. ERR_FAIL_COND_V( p_offset >= MAX_LOOKAHEAD, -1);
  825. int ofs = (TK_RB_SIZE + tk_rb_pos + p_offset - MAX_LOOKAHEAD -1)%TK_RB_SIZE;
  826. return tk_rb[ofs].line;
  827. }
  828. int GDTokenizerText::get_token_column(int p_offset) const {
  829. ERR_FAIL_COND_V( p_offset <= -MAX_LOOKAHEAD, -1);
  830. ERR_FAIL_COND_V( p_offset >= MAX_LOOKAHEAD, -1);
  831. int ofs = (TK_RB_SIZE + tk_rb_pos + p_offset - MAX_LOOKAHEAD -1)%TK_RB_SIZE;
  832. return tk_rb[ofs].col;
  833. }
  834. const Variant& GDTokenizerText::get_token_constant(int p_offset) const {
  835. ERR_FAIL_COND_V( p_offset <= -MAX_LOOKAHEAD, tk_rb[0].constant);
  836. ERR_FAIL_COND_V( p_offset >= MAX_LOOKAHEAD, tk_rb[0].constant);
  837. int ofs = (TK_RB_SIZE + tk_rb_pos + p_offset - MAX_LOOKAHEAD -1)%TK_RB_SIZE;
  838. ERR_FAIL_COND_V(tk_rb[ofs].type!=TK_CONSTANT,tk_rb[0].constant);
  839. return tk_rb[ofs].constant;
  840. }
  841. StringName GDTokenizerText::get_token_identifier(int p_offset) const {
  842. ERR_FAIL_COND_V( p_offset <= -MAX_LOOKAHEAD, StringName());
  843. ERR_FAIL_COND_V( p_offset >= MAX_LOOKAHEAD, StringName());
  844. int ofs = (TK_RB_SIZE + tk_rb_pos + p_offset - MAX_LOOKAHEAD -1)%TK_RB_SIZE;
  845. ERR_FAIL_COND_V(tk_rb[ofs].type!=TK_IDENTIFIER,StringName());
  846. return tk_rb[ofs].identifier;
  847. }
  848. GDFunctions::Function GDTokenizerText::get_token_built_in_func(int p_offset) const {
  849. ERR_FAIL_COND_V( p_offset <= -MAX_LOOKAHEAD, GDFunctions::FUNC_MAX);
  850. ERR_FAIL_COND_V( p_offset >= MAX_LOOKAHEAD, GDFunctions::FUNC_MAX);
  851. int ofs = (TK_RB_SIZE + tk_rb_pos + p_offset - MAX_LOOKAHEAD -1)%TK_RB_SIZE;
  852. ERR_FAIL_COND_V(tk_rb[ofs].type!=TK_BUILT_IN_FUNC,GDFunctions::FUNC_MAX);
  853. return tk_rb[ofs].func;
  854. }
  855. Variant::Type GDTokenizerText::get_token_type(int p_offset) const {
  856. ERR_FAIL_COND_V( p_offset <= -MAX_LOOKAHEAD, Variant::NIL);
  857. ERR_FAIL_COND_V( p_offset >= MAX_LOOKAHEAD, Variant::NIL);
  858. int ofs = (TK_RB_SIZE + tk_rb_pos + p_offset - MAX_LOOKAHEAD -1)%TK_RB_SIZE;
  859. ERR_FAIL_COND_V(tk_rb[ofs].type!=TK_BUILT_IN_TYPE,Variant::NIL);
  860. return tk_rb[ofs].vtype;
  861. }
  862. int GDTokenizerText::get_token_line_indent(int p_offset) const {
  863. ERR_FAIL_COND_V( p_offset <= -MAX_LOOKAHEAD, 0);
  864. ERR_FAIL_COND_V( p_offset >= MAX_LOOKAHEAD, 0);
  865. int ofs = (TK_RB_SIZE + tk_rb_pos + p_offset - MAX_LOOKAHEAD -1)%TK_RB_SIZE;
  866. ERR_FAIL_COND_V(tk_rb[ofs].type!=TK_NEWLINE,0);
  867. return tk_rb[ofs].constant;
  868. }
  869. String GDTokenizerText::get_token_error(int p_offset) const {
  870. ERR_FAIL_COND_V( p_offset <= -MAX_LOOKAHEAD, String());
  871. ERR_FAIL_COND_V( p_offset >= MAX_LOOKAHEAD, String());
  872. int ofs = (TK_RB_SIZE + tk_rb_pos + p_offset - MAX_LOOKAHEAD -1)%TK_RB_SIZE;
  873. ERR_FAIL_COND_V(tk_rb[ofs].type!=TK_ERROR,String());
  874. return tk_rb[ofs].constant;
  875. }
  876. void GDTokenizerText::advance(int p_amount) {
  877. ERR_FAIL_COND( p_amount <=0 );
  878. for(int i=0;i<p_amount;i++)
  879. _advance();
  880. }
  881. //////////////////////////////////////////////////////////////////////////////////////////////////////
  882. #define BYTECODE_VERSION 12
  883. Error GDTokenizerBuffer::set_code_buffer(const Vector<uint8_t> & p_buffer) {
  884. const uint8_t *buf=p_buffer.ptr();
  885. int total_len=p_buffer.size();
  886. ERR_FAIL_COND_V( p_buffer.size()<24 || p_buffer[0]!='G' || p_buffer[1]!='D' || p_buffer[2]!='S' || p_buffer[3]!='C',ERR_INVALID_DATA);
  887. int version = decode_uint32(&buf[4]);
  888. if (version>BYTECODE_VERSION) {
  889. ERR_EXPLAIN("Bytecode is too New! Please use a newer engine version.");
  890. ERR_FAIL_COND_V(version>BYTECODE_VERSION,ERR_INVALID_DATA);
  891. }
  892. int identifier_count = decode_uint32(&buf[8]);
  893. int constant_count = decode_uint32(&buf[12]);
  894. int line_count = decode_uint32(&buf[16]);
  895. int token_count = decode_uint32(&buf[20]);
  896. const uint8_t *b=buf;
  897. b=&buf[24];
  898. total_len-=24;
  899. identifiers.resize(identifier_count);
  900. for(int i=0;i<identifier_count;i++) {
  901. int len = decode_uint32(b);
  902. ERR_FAIL_COND_V(len>total_len,ERR_INVALID_DATA);
  903. b+=4;
  904. Vector<uint8_t> cs;
  905. cs.resize(len);
  906. for(int j=0;j<len;j++) {
  907. cs[j]=b[j]^0xb6;
  908. }
  909. cs[cs.size()-1]=0;
  910. String s;
  911. s.parse_utf8((const char*)cs.ptr());
  912. b+=len;
  913. total_len-=len+4;
  914. identifiers[i]=s;
  915. }
  916. constants.resize(constant_count);
  917. for(int i=0;i<constant_count;i++) {
  918. Variant v;
  919. int len;
  920. Error err = decode_variant(v,b,total_len,&len);
  921. if (err)
  922. return err;
  923. b+=len;
  924. total_len-=len;
  925. constants[i]=v;
  926. }
  927. ERR_FAIL_COND_V(line_count*8>total_len,ERR_INVALID_DATA);
  928. for(int i=0;i<line_count;i++) {
  929. uint32_t token=decode_uint32(b);
  930. b+=4;
  931. uint32_t linecol=decode_uint32(b);
  932. b+=4;
  933. lines.insert(token,linecol);
  934. total_len-=8;
  935. }
  936. tokens.resize(token_count);
  937. for(int i=0;i<token_count;i++) {
  938. ERR_FAIL_COND_V( total_len < 1, ERR_INVALID_DATA);
  939. if ((*b)&TOKEN_BYTE_MASK) { //little endian always
  940. ERR_FAIL_COND_V( total_len < 4, ERR_INVALID_DATA);
  941. tokens[i]=decode_uint32(b)&~TOKEN_BYTE_MASK;
  942. b+=4;
  943. } else {
  944. tokens[i]=*b;
  945. b+=1;
  946. total_len--;
  947. }
  948. }
  949. token=0;
  950. return OK;
  951. }
  952. Vector<uint8_t> GDTokenizerBuffer::parse_code_string(const String& p_code) {
  953. Vector<uint8_t> buf;
  954. Map<StringName,int> identifier_map;
  955. HashMap<Variant,int,VariantHasher> constant_map;
  956. Map<uint32_t,int> line_map;
  957. Vector<uint32_t> token_array;
  958. GDTokenizerText tt;
  959. tt.set_code(p_code);
  960. int line=-1;
  961. while(true) {
  962. if (tt.get_token_line()!=line) {
  963. line=tt.get_token_line();
  964. line_map[line]=token_array.size();
  965. }
  966. uint32_t token=tt.get_token();
  967. switch(tt.get_token()) {
  968. case TK_IDENTIFIER: {
  969. StringName id = tt.get_token_identifier();
  970. if (!identifier_map.has(id)) {
  971. int idx = identifier_map.size();
  972. identifier_map[id]=idx;
  973. }
  974. token|=identifier_map[id]<<TOKEN_BITS;
  975. } break;
  976. case TK_CONSTANT: {
  977. Variant c = tt.get_token_constant();
  978. if (!constant_map.has(c)) {
  979. int idx = constant_map.size();
  980. constant_map[c]=idx;
  981. }
  982. token|=constant_map[c]<<TOKEN_BITS;
  983. } break;
  984. case TK_BUILT_IN_TYPE: {
  985. token|=tt.get_token_type()<<TOKEN_BITS;
  986. } break;
  987. case TK_BUILT_IN_FUNC: {
  988. token|=tt.get_token_built_in_func()<<TOKEN_BITS;
  989. } break;
  990. case TK_NEWLINE: {
  991. token|=tt.get_token_line_indent()<<TOKEN_BITS;
  992. } break;
  993. case TK_ERROR: {
  994. ERR_FAIL_V(Vector<uint8_t>());
  995. } break;
  996. default: {}
  997. };
  998. token_array.push_back(token);
  999. if (tt.get_token()==TK_EOF)
  1000. break;
  1001. tt.advance();
  1002. }
  1003. //reverse maps
  1004. Map<int,StringName> rev_identifier_map;
  1005. for(Map<StringName,int>::Element *E=identifier_map.front();E;E=E->next()) {
  1006. rev_identifier_map[E->get()]=E->key();
  1007. }
  1008. Map<int,Variant> rev_constant_map;
  1009. const Variant *K =NULL;
  1010. while((K=constant_map.next(K))) {
  1011. rev_constant_map[constant_map[*K]]=*K;
  1012. }
  1013. Map<int,uint32_t> rev_line_map;
  1014. for(Map<uint32_t,int>::Element *E=line_map.front();E;E=E->next()) {
  1015. rev_line_map[E->get()]=E->key();
  1016. }
  1017. //save header
  1018. buf.resize(24);
  1019. buf[0]='G';
  1020. buf[1]='D';
  1021. buf[2]='S';
  1022. buf[3]='C';
  1023. encode_uint32(BYTECODE_VERSION,&buf[4]);
  1024. encode_uint32(identifier_map.size(),&buf[8]);
  1025. encode_uint32(constant_map.size(),&buf[12]);
  1026. encode_uint32(line_map.size(),&buf[16]);
  1027. encode_uint32(token_array.size(),&buf[20]);
  1028. //save identifiers
  1029. for(Map<int,StringName>::Element *E=rev_identifier_map.front();E;E=E->next()) {
  1030. CharString cs = String(E->get()).utf8();
  1031. int len = cs.length()+1;
  1032. int extra = 4-(len%4);
  1033. if (extra==4)
  1034. extra=0;
  1035. uint8_t ibuf[4];
  1036. encode_uint32(len+extra,ibuf);
  1037. for(int i=0;i<4;i++) {
  1038. buf.push_back(ibuf[i]);
  1039. }
  1040. for(int i=0;i<len;i++) {
  1041. buf.push_back(cs[i]^0xb6);
  1042. }
  1043. for(int i=0;i<extra;i++) {
  1044. buf.push_back(0^0xb6);
  1045. }
  1046. }
  1047. for(Map<int,Variant>::Element *E=rev_constant_map.front();E;E=E->next()) {
  1048. int len;
  1049. Error err = encode_variant(E->get(),NULL,len);
  1050. ERR_FAIL_COND_V(err!=OK,Vector<uint8_t>());
  1051. int pos=buf.size();
  1052. buf.resize(pos+len);
  1053. encode_variant(E->get(),&buf[pos],len);
  1054. }
  1055. for(Map<int,uint32_t>::Element *E=rev_line_map.front();E;E=E->next()) {
  1056. uint8_t ibuf[8];
  1057. encode_uint32(E->key(),&ibuf[0]);
  1058. encode_uint32(E->get(),&ibuf[4]);
  1059. for(int i=0;i<8;i++)
  1060. buf.push_back(ibuf[i]);
  1061. }
  1062. for(int i=0;i<token_array.size();i++) {
  1063. uint32_t token = token_array[i];
  1064. if (token&~TOKEN_MASK) {
  1065. uint8_t buf4[4];
  1066. encode_uint32(token_array[i]|TOKEN_BYTE_MASK,&buf4[0]);
  1067. for(int j=0;j<4;j++) {
  1068. buf.push_back(buf4[j]);
  1069. }
  1070. } else {
  1071. buf.push_back(token);
  1072. }
  1073. }
  1074. return buf;
  1075. }
  1076. GDTokenizerBuffer::Token GDTokenizerBuffer::get_token(int p_offset) const {
  1077. int offset = token+p_offset;
  1078. if (offset<0 || offset>=tokens.size())
  1079. return TK_EOF;
  1080. return GDTokenizerBuffer::Token(tokens[offset]&TOKEN_MASK);
  1081. }
  1082. StringName GDTokenizerBuffer::get_token_identifier(int p_offset) const{
  1083. int offset = token+p_offset;
  1084. ERR_FAIL_INDEX_V(offset,tokens.size(),StringName());
  1085. uint32_t identifier = tokens[offset]>>TOKEN_BITS;
  1086. ERR_FAIL_INDEX_V(identifier,(uint32_t)identifiers.size(),StringName());
  1087. return identifiers[identifier];
  1088. }
  1089. GDFunctions::Function GDTokenizerBuffer::get_token_built_in_func(int p_offset) const{
  1090. int offset = token+p_offset;
  1091. ERR_FAIL_INDEX_V(offset,tokens.size(),GDFunctions::FUNC_MAX);
  1092. return GDFunctions::Function(tokens[offset]>>TOKEN_BITS);
  1093. }
  1094. Variant::Type GDTokenizerBuffer::get_token_type(int p_offset) const{
  1095. int offset = token+p_offset;
  1096. ERR_FAIL_INDEX_V(offset,tokens.size(),Variant::NIL);
  1097. return Variant::Type(tokens[offset]>>TOKEN_BITS);
  1098. }
  1099. int GDTokenizerBuffer::get_token_line(int p_offset) const{
  1100. int offset = token+p_offset;
  1101. int pos = lines.find_nearest(offset);
  1102. if (pos<0)
  1103. return -1;
  1104. if (pos>=lines.size())
  1105. pos=lines.size()-1;
  1106. uint32_t l = lines.getv(pos);
  1107. return l&TOKEN_LINE_MASK;
  1108. }
  1109. int GDTokenizerBuffer::get_token_column(int p_offset) const{
  1110. int offset = token+p_offset;
  1111. int pos = lines.find_nearest(offset);
  1112. if (pos<0)
  1113. return -1;
  1114. if (pos>=lines.size())
  1115. pos=lines.size()-1;
  1116. uint32_t l = lines.getv(pos);
  1117. return l>>TOKEN_LINE_BITS;
  1118. }
  1119. int GDTokenizerBuffer::get_token_line_indent(int p_offset) const{
  1120. int offset = token+p_offset;
  1121. ERR_FAIL_INDEX_V(offset,tokens.size(),0);
  1122. return tokens[offset]>>TOKEN_BITS;
  1123. }
  1124. const Variant& GDTokenizerBuffer::get_token_constant(int p_offset) const{
  1125. int offset = token+p_offset;
  1126. ERR_FAIL_INDEX_V(offset,tokens.size(),nil);
  1127. uint32_t constant = tokens[offset]>>TOKEN_BITS;
  1128. ERR_FAIL_INDEX_V(constant,(uint32_t)constants.size(),nil);
  1129. return constants[constant];
  1130. }
  1131. String GDTokenizerBuffer::get_token_error(int p_offset) const{
  1132. ERR_FAIL_V(String());
  1133. }
  1134. void GDTokenizerBuffer::advance(int p_amount){
  1135. ERR_FAIL_INDEX(p_amount+token,tokens.size());
  1136. token+=p_amount;
  1137. }
  1138. GDTokenizerBuffer::GDTokenizerBuffer(){
  1139. token=0;
  1140. }