| 445 | } |
| 446 | |
| 447 | Error GDScriptParser::parse_binary(const Vector<uint8_t> &p_binary, const String &p_script_path) { |
| 448 | GDScriptTokenizerBuffer *buffer_tokenizer = memnew(GDScriptTokenizerBuffer); |
| 449 | Error err = buffer_tokenizer->set_code_buffer(p_binary); |
| 450 | |
| 451 | if (err) { |
| 452 | memdelete(buffer_tokenizer); |
| 453 | return err; |
| 454 | } |
| 455 | |
| 456 | tokenizer = buffer_tokenizer; |
| 457 | script_path = p_script_path.simplify_path(); |
| 458 | current = tokenizer->scan(); |
| 459 | // Avoid error or newline as the first token. |
| 460 | // The latter can mess with the parser when opening files filled exclusively with comments and newlines. |
| 461 | while (current.type == GDScriptTokenizer::Token::ERROR || current.type == GDScriptTokenizer::Token::NEWLINE) { |
| 462 | if (current.type == GDScriptTokenizer::Token::ERROR) { |
| 463 | push_error(current.literal); |
| 464 | } |
| 465 | current = tokenizer->scan(); |
| 466 | } |
| 467 | |
| 468 | push_multiline(false); // Keep one for the whole parsing. |
| 469 | parse_program(); |
| 470 | pop_multiline(); |
| 471 | |
| 472 | memdelete(buffer_tokenizer); |
| 473 | tokenizer = nullptr; |
| 474 | |
| 475 | if (errors.is_empty()) { |
| 476 | return OK; |
| 477 | } else { |
| 478 | return ERR_PARSE_ERROR; |
| 479 | } |
| 480 | } |
| 481 | |
| 482 | GDScriptTokenizer::Token GDScriptParser::advance() { |
| 483 | lambda_ended = false; // Empty marker since we're past the end in any case. |