script_class_parser.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753
  1. /*************************************************************************/
  2. /* script_class_parser.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /*************************************************************************/
  30. #include "script_class_parser.h"
  31. #include "core/map.h"
  32. #include "core/os/os.h"
  33. #include "../utils/string_utils.h"
  34. const char *ScriptClassParser::token_names[ScriptClassParser::TK_MAX] = {
  35. "[",
  36. "]",
  37. "{",
  38. "}",
  39. ".",
  40. ":",
  41. ",",
  42. "Symbol",
  43. "Identifier",
  44. "String",
  45. "Number",
  46. "<",
  47. ">",
  48. "EOF",
  49. "Error"
  50. };
  51. String ScriptClassParser::get_token_name(ScriptClassParser::Token p_token) {
  52. ERR_FAIL_INDEX_V(p_token, TK_MAX, "<error>");
  53. return token_names[p_token];
  54. }
  55. ScriptClassParser::Token ScriptClassParser::get_token() {
  56. while (true) {
  57. switch (code[idx]) {
  58. case '\n': {
  59. line++;
  60. idx++;
  61. break;
  62. };
  63. case 0: {
  64. return TK_EOF;
  65. } break;
  66. case '{': {
  67. idx++;
  68. return TK_CURLY_BRACKET_OPEN;
  69. };
  70. case '}': {
  71. idx++;
  72. return TK_CURLY_BRACKET_CLOSE;
  73. };
  74. case '[': {
  75. idx++;
  76. return TK_BRACKET_OPEN;
  77. };
  78. case ']': {
  79. idx++;
  80. return TK_BRACKET_CLOSE;
  81. };
  82. case '<': {
  83. idx++;
  84. return TK_OP_LESS;
  85. };
  86. case '>': {
  87. idx++;
  88. return TK_OP_GREATER;
  89. };
  90. case ':': {
  91. idx++;
  92. return TK_COLON;
  93. };
  94. case ',': {
  95. idx++;
  96. return TK_COMMA;
  97. };
  98. case '.': {
  99. idx++;
  100. return TK_PERIOD;
  101. };
  102. case '#': {
  103. //compiler directive
  104. while (code[idx] != '\n' && code[idx] != 0) {
  105. idx++;
  106. }
  107. continue;
  108. } break;
  109. case '/': {
  110. switch (code[idx + 1]) {
  111. case '*': { // block comment
  112. idx += 2;
  113. while (true) {
  114. if (code[idx] == 0) {
  115. error_str = "Unterminated comment";
  116. error = true;
  117. return TK_ERROR;
  118. } else if (code[idx] == '*' && code[idx + 1] == '/') {
  119. idx += 2;
  120. break;
  121. } else if (code[idx] == '\n') {
  122. line++;
  123. }
  124. idx++;
  125. }
  126. } break;
  127. case '/': { // line comment skip
  128. while (code[idx] != '\n' && code[idx] != 0) {
  129. idx++;
  130. }
  131. } break;
  132. default: {
  133. value = "/";
  134. idx++;
  135. return TK_SYMBOL;
  136. }
  137. }
  138. continue; // a comment
  139. } break;
  140. case '\'':
  141. case '"': {
  142. bool verbatim = idx != 0 && code[idx - 1] == '@';
  143. CharType begin_str = code[idx];
  144. idx++;
  145. String tk_string = String();
  146. while (true) {
  147. if (code[idx] == 0) {
  148. error_str = "Unterminated String";
  149. error = true;
  150. return TK_ERROR;
  151. } else if (code[idx] == begin_str) {
  152. if (verbatim && code[idx + 1] == '"') { // '""' is verbatim string's '\"'
  153. idx += 2; // skip next '"' as well
  154. continue;
  155. }
  156. idx += 1;
  157. break;
  158. } else if (code[idx] == '\\' && !verbatim) {
  159. //escaped characters...
  160. idx++;
  161. CharType next = code[idx];
  162. if (next == 0) {
  163. error_str = "Unterminated String";
  164. error = true;
  165. return TK_ERROR;
  166. }
  167. CharType res = 0;
  168. switch (next) {
  169. case 'b':
  170. res = 8;
  171. break;
  172. case 't':
  173. res = 9;
  174. break;
  175. case 'n':
  176. res = 10;
  177. break;
  178. case 'f':
  179. res = 12;
  180. break;
  181. case 'r':
  182. res = 13;
  183. break;
  184. case '\"':
  185. res = '\"';
  186. break;
  187. case '\\':
  188. res = '\\';
  189. break;
  190. default: {
  191. res = next;
  192. } break;
  193. }
  194. tk_string += res;
  195. } else {
  196. if (code[idx] == '\n') {
  197. line++;
  198. }
  199. tk_string += code[idx];
  200. }
  201. idx++;
  202. }
  203. value = tk_string;
  204. return TK_STRING;
  205. } break;
  206. default: {
  207. if (code[idx] <= 32) {
  208. idx++;
  209. break;
  210. }
  211. if ((code[idx] >= 33 && code[idx] <= 47) || (code[idx] >= 58 && code[idx] <= 63) || (code[idx] >= 91 && code[idx] <= 94) || code[idx] == 96 || (code[idx] >= 123 && code[idx] <= 127)) {
  212. value = String::chr(code[idx]);
  213. idx++;
  214. return TK_SYMBOL;
  215. }
  216. if (code[idx] == '-' || (code[idx] >= '0' && code[idx] <= '9')) {
  217. //a number
  218. const CharType *rptr;
  219. double number = String::to_float(&code[idx], &rptr);
  220. idx += (rptr - &code[idx]);
  221. value = number;
  222. return TK_NUMBER;
  223. } else if ((code[idx] == '@' && code[idx + 1] != '"') || code[idx] == '_' || (code[idx] >= 'A' && code[idx] <= 'Z') || (code[idx] >= 'a' && code[idx] <= 'z') || code[idx] > 127) {
  224. String id;
  225. id += code[idx];
  226. idx++;
  227. while (code[idx] == '_' || (code[idx] >= 'A' && code[idx] <= 'Z') || (code[idx] >= 'a' && code[idx] <= 'z') || (code[idx] >= '0' && code[idx] <= '9') || code[idx] > 127) {
  228. id += code[idx];
  229. idx++;
  230. }
  231. value = id;
  232. return TK_IDENTIFIER;
  233. } else if (code[idx] == '@' && code[idx + 1] == '"') {
  234. // begin of verbatim string
  235. idx++;
  236. } else {
  237. error_str = "Unexpected character.";
  238. error = true;
  239. return TK_ERROR;
  240. }
  241. }
  242. }
  243. }
  244. }
  245. Error ScriptClassParser::_skip_generic_type_params() {
  246. Token tk;
  247. while (true) {
  248. tk = get_token();
  249. if (tk == TK_IDENTIFIER) {
  250. tk = get_token();
  251. // Type specifications can end with "?" to denote nullable types, such as IList<int?>
  252. if (tk == TK_SYMBOL) {
  253. tk = get_token();
  254. if (value.operator String() != "?") {
  255. error_str = "Expected " + get_token_name(TK_IDENTIFIER) + ", found unexpected symbol '" + value + "'";
  256. error = true;
  257. return ERR_PARSE_ERROR;
  258. }
  259. if (tk != TK_OP_GREATER && tk != TK_COMMA) {
  260. error_str = "Nullable type symbol '?' is only allowed after an identifier, but found " + get_token_name(tk) + " next.";
  261. error = true;
  262. return ERR_PARSE_ERROR;
  263. }
  264. }
  265. if (tk == TK_PERIOD) {
  266. while (true) {
  267. tk = get_token();
  268. if (tk != TK_IDENTIFIER) {
  269. error_str = "Expected " + get_token_name(TK_IDENTIFIER) + ", found: " + get_token_name(tk);
  270. error = true;
  271. return ERR_PARSE_ERROR;
  272. }
  273. tk = get_token();
  274. if (tk != TK_PERIOD) {
  275. break;
  276. }
  277. }
  278. }
  279. if (tk == TK_OP_LESS) {
  280. Error err = _skip_generic_type_params();
  281. if (err) {
  282. return err;
  283. }
  284. tk = get_token();
  285. }
  286. if (tk == TK_OP_GREATER) {
  287. return OK;
  288. } else if (tk != TK_COMMA) {
  289. error_str = "Unexpected token: " + get_token_name(tk);
  290. error = true;
  291. return ERR_PARSE_ERROR;
  292. }
  293. } else if (tk == TK_OP_LESS) {
  294. error_str = "Expected " + get_token_name(TK_IDENTIFIER) + ", found " + get_token_name(TK_OP_LESS);
  295. error = true;
  296. return ERR_PARSE_ERROR;
  297. } else if (tk == TK_OP_GREATER) {
  298. return OK;
  299. } else {
  300. error_str = "Unexpected token: " + get_token_name(tk);
  301. error = true;
  302. return ERR_PARSE_ERROR;
  303. }
  304. }
  305. }
  306. Error ScriptClassParser::_parse_type_full_name(String &r_full_name) {
  307. Token tk = get_token();
  308. if (tk != TK_IDENTIFIER) {
  309. error_str = "Expected " + get_token_name(TK_IDENTIFIER) + ", found: " + get_token_name(tk);
  310. error = true;
  311. return ERR_PARSE_ERROR;
  312. }
  313. r_full_name += String(value);
  314. if (code[idx] == '<') {
  315. idx++;
  316. // We don't mind if the base is generic, but we skip it any ways since this information is not needed
  317. Error err = _skip_generic_type_params();
  318. if (err) {
  319. return err;
  320. }
  321. }
  322. if (code[idx] != '.') { // We only want to take the next token if it's a period
  323. return OK;
  324. }
  325. tk = get_token();
  326. CRASH_COND(tk != TK_PERIOD); // Assertion
  327. r_full_name += ".";
  328. return _parse_type_full_name(r_full_name);
  329. }
  330. Error ScriptClassParser::_parse_class_base(Vector<String> &r_base) {
  331. String name;
  332. Error err = _parse_type_full_name(name);
  333. if (err) {
  334. return err;
  335. }
  336. Token tk = get_token();
  337. if (tk == TK_COMMA) {
  338. err = _parse_class_base(r_base);
  339. if (err) {
  340. return err;
  341. }
  342. } else if (tk == TK_IDENTIFIER && String(value) == "where") {
  343. err = _parse_type_constraints();
  344. if (err) {
  345. return err;
  346. }
  347. // An open curly bracket was parsed by _parse_type_constraints, so we can exit
  348. } else if (tk == TK_CURLY_BRACKET_OPEN) {
  349. // we are finished when we hit the open curly bracket
  350. } else {
  351. error_str = "Unexpected token: " + get_token_name(tk);
  352. error = true;
  353. return ERR_PARSE_ERROR;
  354. }
  355. r_base.push_back(name);
  356. return OK;
  357. }
  358. Error ScriptClassParser::_parse_type_constraints() {
  359. Token tk = get_token();
  360. if (tk != TK_IDENTIFIER) {
  361. error_str = "Unexpected token: " + get_token_name(tk);
  362. error = true;
  363. return ERR_PARSE_ERROR;
  364. }
  365. tk = get_token();
  366. if (tk != TK_COLON) {
  367. error_str = "Unexpected token: " + get_token_name(tk);
  368. error = true;
  369. return ERR_PARSE_ERROR;
  370. }
  371. while (true) {
  372. tk = get_token();
  373. if (tk == TK_IDENTIFIER) {
  374. if (String(value) == "where") {
  375. return _parse_type_constraints();
  376. }
  377. tk = get_token();
  378. if (tk == TK_PERIOD) {
  379. while (true) {
  380. tk = get_token();
  381. if (tk != TK_IDENTIFIER) {
  382. error_str = "Expected " + get_token_name(TK_IDENTIFIER) + ", found: " + get_token_name(tk);
  383. error = true;
  384. return ERR_PARSE_ERROR;
  385. }
  386. tk = get_token();
  387. if (tk != TK_PERIOD) {
  388. break;
  389. }
  390. }
  391. }
  392. }
  393. if (tk == TK_COMMA) {
  394. continue;
  395. } else if (tk == TK_IDENTIFIER && String(value) == "where") {
  396. return _parse_type_constraints();
  397. } else if (tk == TK_SYMBOL && String(value) == "(") {
  398. tk = get_token();
  399. if (tk != TK_SYMBOL || String(value) != ")") {
  400. error_str = "Unexpected token: " + get_token_name(tk);
  401. error = true;
  402. return ERR_PARSE_ERROR;
  403. }
  404. } else if (tk == TK_OP_LESS) {
  405. Error err = _skip_generic_type_params();
  406. if (err) {
  407. return err;
  408. }
  409. } else if (tk == TK_CURLY_BRACKET_OPEN) {
  410. return OK;
  411. } else {
  412. error_str = "Unexpected token: " + get_token_name(tk);
  413. error = true;
  414. return ERR_PARSE_ERROR;
  415. }
  416. }
  417. }
  418. Error ScriptClassParser::_parse_namespace_name(String &r_name, int &r_curly_stack) {
  419. Token tk = get_token();
  420. if (tk == TK_IDENTIFIER) {
  421. r_name += String(value);
  422. } else {
  423. error_str = "Unexpected token: " + get_token_name(tk);
  424. error = true;
  425. return ERR_PARSE_ERROR;
  426. }
  427. tk = get_token();
  428. if (tk == TK_PERIOD) {
  429. r_name += ".";
  430. return _parse_namespace_name(r_name, r_curly_stack);
  431. } else if (tk == TK_CURLY_BRACKET_OPEN) {
  432. r_curly_stack++;
  433. return OK;
  434. } else {
  435. error_str = "Unexpected token: " + get_token_name(tk);
  436. error = true;
  437. return ERR_PARSE_ERROR;
  438. }
  439. }
  440. Error ScriptClassParser::parse(const String &p_code) {
  441. code = p_code;
  442. idx = 0;
  443. line = 0;
  444. error_str = String();
  445. error = false;
  446. value = Variant();
  447. classes.clear();
  448. Token tk = get_token();
  449. Map<int, NameDecl> name_stack;
  450. int curly_stack = 0;
  451. int type_curly_stack = 0;
  452. while (!error && tk != TK_EOF) {
  453. String identifier = value;
  454. if (tk == TK_IDENTIFIER && (identifier == "class" || identifier == "struct")) {
  455. bool is_class = identifier == "class";
  456. tk = get_token();
  457. if (tk == TK_IDENTIFIER) {
  458. String name = value;
  459. int at_level = curly_stack;
  460. ClassDecl class_decl;
  461. for (Map<int, NameDecl>::Element *E = name_stack.front(); E; E = E->next()) {
  462. const NameDecl &name_decl = E->value();
  463. if (name_decl.type == NameDecl::NAMESPACE_DECL) {
  464. if (E != name_stack.front()) {
  465. class_decl.namespace_ += ".";
  466. }
  467. class_decl.namespace_ += name_decl.name;
  468. } else {
  469. class_decl.name += name_decl.name + ".";
  470. }
  471. }
  472. class_decl.name += name;
  473. class_decl.nested = type_curly_stack > 0;
  474. bool generic = false;
  475. while (true) {
  476. tk = get_token();
  477. if (tk == TK_COLON) {
  478. Error err = _parse_class_base(class_decl.base);
  479. if (err) {
  480. return err;
  481. }
  482. curly_stack++;
  483. type_curly_stack++;
  484. break;
  485. } else if (tk == TK_CURLY_BRACKET_OPEN) {
  486. curly_stack++;
  487. type_curly_stack++;
  488. break;
  489. } else if (tk == TK_OP_LESS && !generic) {
  490. generic = true;
  491. Error err = _skip_generic_type_params();
  492. if (err) {
  493. return err;
  494. }
  495. } else if (tk == TK_IDENTIFIER && String(value) == "where") {
  496. Error err = _parse_type_constraints();
  497. if (err) {
  498. return err;
  499. }
  500. // An open curly bracket was parsed by _parse_type_constraints, so we can exit
  501. curly_stack++;
  502. type_curly_stack++;
  503. break;
  504. } else {
  505. error_str = "Unexpected token: " + get_token_name(tk);
  506. error = true;
  507. return ERR_PARSE_ERROR;
  508. }
  509. }
  510. NameDecl name_decl;
  511. name_decl.name = name;
  512. name_decl.type = is_class ? NameDecl::CLASS_DECL : NameDecl::STRUCT_DECL;
  513. name_stack[at_level] = name_decl;
  514. if (is_class) {
  515. if (!generic) { // no generics, thanks
  516. classes.push_back(class_decl);
  517. } else if (OS::get_singleton()->is_stdout_verbose()) {
  518. String full_name = class_decl.namespace_;
  519. if (full_name.length()) {
  520. full_name += ".";
  521. }
  522. full_name += class_decl.name;
  523. OS::get_singleton()->print("Ignoring generic class declaration: %s\n", full_name.utf8().get_data());
  524. }
  525. }
  526. }
  527. } else if (tk == TK_IDENTIFIER && identifier == "namespace") {
  528. if (type_curly_stack > 0) {
  529. error_str = "Found namespace nested inside type.";
  530. error = true;
  531. return ERR_PARSE_ERROR;
  532. }
  533. String name;
  534. int at_level = curly_stack;
  535. Error err = _parse_namespace_name(name, curly_stack);
  536. if (err) {
  537. return err;
  538. }
  539. NameDecl name_decl;
  540. name_decl.name = name;
  541. name_decl.type = NameDecl::NAMESPACE_DECL;
  542. name_stack[at_level] = name_decl;
  543. } else if (tk == TK_CURLY_BRACKET_OPEN) {
  544. curly_stack++;
  545. } else if (tk == TK_CURLY_BRACKET_CLOSE) {
  546. curly_stack--;
  547. if (name_stack.has(curly_stack)) {
  548. if (name_stack[curly_stack].type != NameDecl::NAMESPACE_DECL) {
  549. type_curly_stack--;
  550. }
  551. name_stack.erase(curly_stack);
  552. }
  553. }
  554. tk = get_token();
  555. }
  556. if (!error && tk == TK_EOF && curly_stack > 0) {
  557. error_str = "Reached EOF with missing close curly brackets.";
  558. error = true;
  559. }
  560. if (error) {
  561. return ERR_PARSE_ERROR;
  562. }
  563. return OK;
  564. }
  565. static String get_preprocessor_directive(const String &p_line, int p_from) {
  566. CRASH_COND(p_line[p_from] != '#');
  567. p_from++;
  568. int i = p_from;
  569. while (i < p_line.length() && (p_line[i] == '_' || (p_line[i] >= 'A' && p_line[i] <= 'Z') ||
  570. (p_line[i] >= 'a' && p_line[i] <= 'z') || p_line[i] > 127)) {
  571. i++;
  572. }
  573. return p_line.substr(p_from, i - p_from);
  574. }
  575. static void run_dummy_preprocessor(String &r_source, const String &p_filepath) {
  576. Vector<String> lines = r_source.split("\n", /* p_allow_empty: */ true);
  577. bool *include_lines = memnew_arr(bool, lines.size());
  578. int if_level = -1;
  579. Vector<bool> is_branch_being_compiled;
  580. for (int i = 0; i < lines.size(); i++) {
  581. const String &line = lines[i];
  582. const int line_len = line.length();
  583. int j;
  584. for (j = 0; j < line_len; j++) {
  585. if (line[j] != ' ' && line[j] != '\t') {
  586. if (line[j] == '#') {
  587. // First non-whitespace char of the line is '#'
  588. include_lines[i] = false;
  589. String directive = get_preprocessor_directive(line, j);
  590. if (directive == "if") {
  591. if_level++;
  592. is_branch_being_compiled.push_back(if_level == 0 || is_branch_being_compiled[if_level - 1]);
  593. } else if (directive == "elif") {
  594. ERR_CONTINUE_MSG(if_level == -1, "Found unexpected '#elif' directive. File: '" + p_filepath + "'.");
  595. is_branch_being_compiled.write[if_level] = false;
  596. } else if (directive == "else") {
  597. ERR_CONTINUE_MSG(if_level == -1, "Found unexpected '#else' directive. File: '" + p_filepath + "'.");
  598. is_branch_being_compiled.write[if_level] = false;
  599. } else if (directive == "endif") {
  600. ERR_CONTINUE_MSG(if_level == -1, "Found unexpected '#endif' directive. File: '" + p_filepath + "'.");
  601. is_branch_being_compiled.remove(if_level);
  602. if_level--;
  603. }
  604. break;
  605. } else {
  606. // First non-whitespace char of the line is not '#'
  607. include_lines[i] = if_level == -1 || is_branch_being_compiled[if_level];
  608. break;
  609. }
  610. }
  611. }
  612. if (j == line_len) {
  613. // Loop ended without finding a non-whitespace character.
  614. // Either the line was empty or it only contained whitespaces.
  615. include_lines[i] = if_level == -1 || is_branch_being_compiled[if_level];
  616. }
  617. }
  618. r_source.clear();
  619. // Custom join ignoring lines removed by the preprocessor
  620. for (int i = 0; i < lines.size(); i++) {
  621. if (i > 0 && include_lines[i - 1]) {
  622. r_source += '\n';
  623. }
  624. if (include_lines[i]) {
  625. r_source += lines[i];
  626. }
  627. }
  628. }
  629. Error ScriptClassParser::parse_file(const String &p_filepath) {
  630. String source;
  631. Error ferr = read_all_file_utf8(p_filepath, source);
  632. ERR_FAIL_COND_V_MSG(ferr != OK, ferr,
  633. ferr == ERR_INVALID_DATA ?
  634. "File '" + p_filepath + "' contains invalid unicode (UTF-8), so it was not loaded."
  635. " Please ensure that scripts are saved in valid UTF-8 unicode." :
  636. "Failed to read file: '" + p_filepath + "'.");
  637. run_dummy_preprocessor(source, p_filepath);
  638. return parse(source);
  639. }
  640. String ScriptClassParser::get_error() {
  641. return error_str;
  642. }
  643. Vector<ScriptClassParser::ClassDecl> ScriptClassParser::get_classes() {
  644. return classes;
  645. }