diff options
Diffstat (limited to 'src/yuescript/yue_parser.cpp')
-rwxr-xr-x | src/yuescript/yue_parser.cpp | 19 |
1 files changed, 7 insertions, 12 deletions
diff --git a/src/yuescript/yue_parser.cpp b/src/yuescript/yue_parser.cpp index d6e8c67..0b7f79e 100755 --- a/src/yuescript/yue_parser.cpp +++ b/src/yuescript/yue_parser.cpp | |||
@@ -28,8 +28,8 @@ std::unordered_set<std::string> Keywords = { | |||
28 | "or", "repeat", "return", "then", "true", | 28 | "or", "repeat", "return", "then", "true", |
29 | "until", "while", // Lua keywords | 29 | "until", "while", // Lua keywords |
30 | "as", "class", "continue", "export", "extends", | 30 | "as", "class", "continue", "export", "extends", |
31 | "from", "global", "import", "macro", "switch", | 31 | "from", "global", "import", "is", "macro", |
32 | "unless", "using", "when", "with" // Yue keywords | 32 | "switch", "unless", "using", "when", "with" // Yue keywords |
33 | }; | 33 | }; |
34 | 34 | ||
35 | YueParser::YueParser() { | 35 | YueParser::YueParser() { |
@@ -179,15 +179,10 @@ YueParser::YueParser() { | |||
179 | 179 | ||
180 | local_flag = expr('*') | expr('^'); | 180 | local_flag = expr('*') | expr('^'); |
181 | local_values = NameList >> -(sym('=') >> (TableBlock | ExpListLow)); | 181 | local_values = NameList >> -(sym('=') >> (TableBlock | ExpListLow)); |
182 | Attrib = (expr("const") | expr("close")) >> not_(AlphaNum); | ||
182 | Local = key("local") >> (Space >> local_flag | local_values); | 183 | Local = key("local") >> (Space >> local_flag | local_values); |
183 | 184 | ||
184 | LocalAttrib = and_(key(pl::user(Name, [](const item_t& item) { | 185 | LocalAttrib = Space >> Attrib >> NameList >> Assign; |
185 | State* st = reinterpret_cast<State*>(item.user_data); | ||
186 | for (auto it = item.begin; it != item.end; ++it) st->buffer += static_cast<char>(*it); | ||
187 | auto it = Keywords.find(st->buffer); | ||
188 | st->buffer.clear(); | ||
189 | return it == Keywords.end(); | ||
190 | })) >> NameList >> sym('=') >> not_('=')) >> Space >> Name >> NameList >> Assign; | ||
191 | 186 | ||
192 | colon_import_name = sym('\\') >> Space >> Variable; | 187 | colon_import_name = sym('\\') >> Space >> Variable; |
193 | ImportName = colon_import_name | Space >> Variable; | 188 | ImportName = colon_import_name | Space >> Variable; |
@@ -626,8 +621,8 @@ YueParser::YueParser() { | |||
626 | Statement = ( | 621 | Statement = ( |
627 | Import | While | Repeat | For | ForEach | | 622 | Import | While | Repeat | For | ForEach | |
628 | Return | Local | Global | Export | Macro | | 623 | Return | Local | Global | Export | Macro | |
629 | Space >> BreakLoop | Label | Goto | Backcall | | 624 | Space >> BreakLoop | Label | Goto | LocalAttrib | |
630 | LocalAttrib | PipeBody | ExpListAssign | 625 | Backcall | PipeBody | ExpListAssign |
631 | ) >> Space >> | 626 | ) >> Space >> |
632 | -statement_appendix >> -statement_sep; | 627 | -statement_appendix >> -statement_sep; |
633 | 628 | ||
@@ -639,7 +634,7 @@ YueParser::YueParser() { | |||
639 | 634 | ||
640 | Shebang = expr("#!") >> *(not_(Stop) >> Any); | 635 | Shebang = expr("#!") >> *(not_(Stop) >> Any); |
641 | BlockEnd = Block >> -(+Break >> Space >> and_(Stop)) >> Stop; | 636 | BlockEnd = Block >> -(+Break >> Space >> and_(Stop)) >> Stop; |
642 | File = White >> -Shebang >> Block >> -(+Break >> Space >> and_(eof())) >> eof(); | 637 | File = White >> -Shebang >> -Block >> White >> eof(); |
643 | } | 638 | } |
644 | 639 | ||
645 | ParseInfo YueParser::parse(std::string_view codes, rule& r) { | 640 | ParseInfo YueParser::parse(std::string_view codes, rule& r) { |