| 671 | } |
| 672 | |
| 673 | std::int32_t ScriptLoader::ExtractDeclaration(StringView scriptContent, std::int32_t pos, String& name, String& declaration, MetadataType& type) |
| 674 | { |
| 675 | std::int32_t scriptSize = (std::int32_t)scriptContent.size(); |
| 676 | std::int32_t start = pos; |
| 677 | |
| 678 | declaration = {}; |
| 679 | type = MetadataType::Unknown; |
| 680 | |
| 681 | StringView token; |
| 682 | std::uint32_t len = 0; |
| 683 | asETokenClass t = asTC_WHITESPACE; |
| 684 | |
| 685 | // Skip white spaces, comments and leading decorators |
| 686 | do { |
| 687 | pos += len; |
| 688 | t = _engine->ParseToken(&scriptContent[pos], scriptSize - pos, &len); |
| 689 | token = scriptContent.sliceSize(pos, len); |
| 690 | } while (t == asTC_WHITESPACE || t == asTC_COMMENT || |
| 691 | token == "private"_s || token == "protected"_s || token == "shared"_s || |
| 692 | token == "external"_s || token == "final"_s || token == "abstract"_s); |
| 693 | |
| 694 | // We're expecting, either a class, interface, function, or variable declaration |
| 695 | if (t == asTC_KEYWORD || t == asTC_IDENTIFIER) { |
| 696 | token = scriptContent.sliceSize(pos, len); |
| 697 | if (token == "interface"_s || token == "class"_s || token == "enum"_s) { |
| 698 | do { |
| 699 | pos += len; |
| 700 | t = _engine->ParseToken(&scriptContent[pos], scriptSize - pos, &len); |
| 701 | } while (t == asTC_WHITESPACE || t == asTC_COMMENT); |
| 702 | |
| 703 | if (t == asTC_IDENTIFIER) { |
| 704 | type = MetadataType::Type; |
| 705 | declaration = scriptContent.slice(pos, pos + len); |
| 706 | pos += len; |
| 707 | return pos; |
| 708 | } |
| 709 | } else { |
| 710 | // For function declarations, store everything up to the start of the |
| 711 | // statement block, except for succeeding decorators (final, override, etc) |
| 712 | // For variable declaration store just the name as there can only be one |
| 713 | |
| 714 | // We'll only know if the declaration is a variable or function declaration |
| 715 | // when we see the statement block, or absense of a statement block. |
| 716 | bool hasParenthesis = false; |
| 717 | std::int32_t nestedParenthesis = 0; |
| 718 | declaration += scriptContent.slice(pos, pos + len); |
| 719 | pos += len; |
| 720 | for (; pos < scriptSize;) { |
| 721 | t = _engine->ParseToken(&scriptContent[pos], scriptSize - pos, &len); |
| 722 | token = scriptContent.sliceSize(pos, len); |
| 723 | if (t == asTC_KEYWORD) { |
| 724 | if (token == "{"_s && nestedParenthesis == 0) { |
| 725 | if (hasParenthesis) { |
| 726 | type = MetadataType::Function; |
| 727 | } else { |
| 728 | declaration = name; |
| 729 | type = MetadataType::VirtualProperty; |
| 730 | } |