diff options
Diffstat (limited to 'src/yuescript/yue_parser.cpp')
| -rw-r--r-- | src/yuescript/yue_parser.cpp | 35 |
1 files changed, 20 insertions, 15 deletions
diff --git a/src/yuescript/yue_parser.cpp b/src/yuescript/yue_parser.cpp index ab1ba7a..b032826 100644 --- a/src/yuescript/yue_parser.cpp +++ b/src/yuescript/yue_parser.cpp | |||
| @@ -393,7 +393,7 @@ YueParser::YueParser() { | |||
| 393 | in_block = space_break >> *(*set(" \t") >> line_break) >> advance_match >> ensure(Block, pop_indent); | 393 | in_block = space_break >> *(*set(" \t") >> line_break) >> advance_match >> ensure(Block, pop_indent); |
| 394 | 394 | ||
| 395 | LocalFlag = expr('*') | '^'; | 395 | LocalFlag = expr('*') | '^'; |
| 396 | LocalValues = NameList >> -(space >> '=' >> space >> (TableBlock | ExpListLow | expected_expression_error)); | 396 | LocalValues = NameList >> -(space >> '=' >> space >> (TableBlock | ExpList | expected_expression_error)); |
| 397 | Local = key("local") >> space >> (LocalFlag | LocalValues | invalid_local_declaration_error); | 397 | Local = key("local") >> space >> (LocalFlag | LocalValues | invalid_local_declaration_error); |
| 398 | 398 | ||
| 399 | ConstAttrib = key("const"); | 399 | ConstAttrib = key("const"); |
| @@ -478,7 +478,7 @@ YueParser::YueParser() { | |||
| 478 | Continue = key("continue"); | 478 | Continue = key("continue"); |
| 479 | BreakLoop = (Break >> -(space >> Exp) | Continue) >> not_alpha_num; | 479 | BreakLoop = (Break >> -(space >> Exp) | Continue) >> not_alpha_num; |
| 480 | 480 | ||
| 481 | Return = key("return") >> -(space >> (TableBlock | ExpListLow)); | 481 | Return = key("return") >> -(space >> (TableBlock | ExpList)); |
| 482 | 482 | ||
| 483 | must_exp = Exp | expected_expression_error; | 483 | must_exp = Exp | expected_expression_error; |
| 484 | 484 | ||
| @@ -674,7 +674,7 @@ YueParser::YueParser() { | |||
| 674 | 674 | ||
| 675 | Assign = '=' >> space >> Seperator >> ( | 675 | Assign = '=' >> space >> Seperator >> ( |
| 676 | With | If | Switch | TableBlock | | 676 | With | If | Switch | TableBlock | |
| 677 | (SpreadListExp | Exp) >> *(space >> set(",;") >> space >> (SpreadListExp | Exp)) | | 677 | (SpreadListExp | Exp) >> *(space >> set(",") >> space >> (SpreadListExp | Exp)) | |
| 678 | expected_expression_error | 678 | expected_expression_error |
| 679 | ); | 679 | ); |
| 680 | 680 | ||
| @@ -927,7 +927,7 @@ YueParser::YueParser() { | |||
| 927 | -(space >> key("using") >> prevent_indent >> space >> ensure(ExpList | expected_expression_error, pop_indent)) | 927 | -(space >> key("using") >> prevent_indent >> space >> ensure(ExpList | expected_expression_error, pop_indent)) |
| 928 | ) >> -ClassBlock; | 928 | ) >> -ClassBlock; |
| 929 | 929 | ||
| 930 | GlobalValues = NameList >> -(space >> '=' >> space >> (TableBlock | ExpListLow | expected_expression_error)); | 930 | GlobalValues = NameList >> -(space >> '=' >> space >> (TableBlock | ExpList | expected_expression_error)); |
| 931 | GlobalOp = expr('*') | '^'; | 931 | GlobalOp = expr('*') | '^'; |
| 932 | Global = key("global") >> space >> ( | 932 | Global = key("global") >> space >> ( |
| 933 | -(ConstAttrib >> space) >> ClassDecl | | 933 | -(ConstAttrib >> space) >> ClassDecl | |
| @@ -1056,7 +1056,7 @@ YueParser::YueParser() { | |||
| 1056 | return st->fnArrowAvailable; | 1056 | return st->fnArrowAvailable; |
| 1057 | }) >> -(FnArgsDef >> | 1057 | }) >> -(FnArgsDef >> |
| 1058 | -(':' >> space >> | 1058 | -(':' >> space >> |
| 1059 | disable_fun_lit >> ensure(ExpListLow | DefaultValue, enable_fun_lit) | 1059 | disable_fun_lit >> ensure(ExpList | DefaultValue, enable_fun_lit) |
| 1060 | ) | 1060 | ) |
| 1061 | ) >> space >> FnArrow >> -(space >> Body); | 1061 | ) >> space >> FnArrow >> -(space >> Body); |
| 1062 | 1062 | ||
| @@ -1087,7 +1087,6 @@ YueParser::YueParser() { | |||
| 1087 | *(+space_break >> check_indent_match >> space >> pipe_operator >> space >> must_unary_exp); | 1087 | *(+space_break >> check_indent_match >> space >> pipe_operator >> space >> must_unary_exp); |
| 1088 | 1088 | ||
| 1089 | ExpList = Seperator >> Exp >> *(space >> ',' >> space >> Exp); | 1089 | ExpList = Seperator >> Exp >> *(space >> ',' >> space >> Exp); |
| 1090 | ExpListLow = Seperator >> Exp >> *(space >> set(",;") >> space >> Exp); | ||
| 1091 | 1090 | ||
| 1092 | arg_line = check_indent_match >> space >> Exp >> *(space >> ',' >> space >> Exp); | 1091 | arg_line = check_indent_match >> space >> Exp >> *(space >> ',' >> space >> Exp); |
| 1093 | arg_block = arg_line >> *(space >> ',' >> space_break >> arg_line) >> pop_indent; | 1092 | arg_block = arg_line >> *(space >> ',' >> space_break >> arg_line) >> pop_indent; |
| @@ -1124,17 +1123,18 @@ YueParser::YueParser() { | |||
| 1124 | 1123 | ||
| 1125 | ChainAssign = Seperator >> Exp >> +(space >> '=' >> space >> Exp >> space >> and_('=')) >> space >> Assign; | 1124 | ChainAssign = Seperator >> Exp >> +(space >> '=' >> space >> Exp >> space >> and_('=')) >> space >> Assign; |
| 1126 | 1125 | ||
| 1127 | StatementAppendix = (IfLine | WhileLine | CompFor) >> space; | 1126 | StatementAppendix = IfLine | WhileLine | CompFor; |
| 1128 | Statement = | 1127 | Statement = ( |
| 1129 | ( | 1128 | ( |
| 1130 | Import | Export | Global | Macro | MacroInPlace | Label | 1129 | Import | Export | Global | Macro | MacroInPlace | Label |
| 1131 | ) >> space | ( | 1130 | ) | ( |
| 1132 | Local | While | Repeat | For | Return | | 1131 | Local | While | Repeat | For | Return | |
| 1133 | BreakLoop | Goto | ShortTabAppending | | 1132 | BreakLoop | Goto | ShortTabAppending | |
| 1134 | LocalAttrib | Backcall | PipeBody | ExpListAssign | ChainAssign | | 1133 | LocalAttrib | Backcall | PipeBody | ExpListAssign | ChainAssign | |
| 1135 | StatementAppendix >> empty_block_error | | 1134 | StatementAppendix >> empty_block_error | |
| 1136 | and_(key("else") | key("elseif") | key("when")) >> dangling_clause_error | 1135 | and_(key("else") | key("elseif") | key("when")) >> dangling_clause_error |
| 1137 | ) >> space >> -StatementAppendix; | 1136 | ) >> space >> -StatementAppendix |
| 1137 | ) >> space; | ||
| 1138 | 1138 | ||
| 1139 | StatementSep = white >> (set("('\"") | "[[" | "[="); | 1139 | StatementSep = white >> (set("('\"") | "[[" | "[="); |
| 1140 | 1140 | ||
| @@ -1158,15 +1158,20 @@ YueParser::YueParser() { | |||
| 1158 | return false; | 1158 | return false; |
| 1159 | }); | 1159 | }); |
| 1160 | 1160 | ||
| 1161 | is_lax = pl::user(true_(), [](const item_t& item) { | ||
| 1162 | State* st = reinterpret_cast<State*>(item.user_data); | ||
| 1163 | return st->lax; | ||
| 1164 | }); | ||
| 1165 | |||
| 1161 | line = *(EmptyLine >> line_break) >> ( | 1166 | line = *(EmptyLine >> line_break) >> ( |
| 1162 | check_indent_match >> space >> Statement | | 1167 | check_indent_match >> space >> Statement >> *(';' >> -(space >> Statement)) | |
| 1163 | YueComment | | 1168 | YueComment | |
| 1164 | advance_match >> ensure(space >> (indentation_error | Statement), pop_indent) | 1169 | advance_match >> ensure(space >> (indentation_error | Statement), pop_indent) |
| 1165 | ); | 1170 | ); |
| 1166 | Block = Seperator >> (pl::user(true_(), [](const item_t& item) { | 1171 | Block = Seperator >> ( |
| 1167 | State* st = reinterpret_cast<State*>(item.user_data); | 1172 | is_lax >> lax_line >> *(line_break >> lax_line) | |
| 1168 | return st->lax; | 1173 | line >> *(line_break >> line) |
| 1169 | }) >> lax_line >> *(line_break >> lax_line) | line >> *(line_break >> line)); | 1174 | ); |
| 1170 | 1175 | ||
| 1171 | shebang = "#!" >> *(not_(stop) >> any_char); | 1176 | shebang = "#!" >> *(not_(stop) >> any_char); |
| 1172 | BlockEnd = Block >> plain_white >> stop; | 1177 | BlockEnd = Block >> plain_white >> stop; |
