diff options
| author | Li Jin <dragon-fly@qq.com> | 2023-01-19 18:06:03 +0800 |
|---|---|---|
| committer | Li Jin <dragon-fly@qq.com> | 2023-01-19 18:06:03 +0800 |
| commit | 2fad28df04f2c8f015ccf90e16e74c47ad174bde (patch) | |
| tree | 11249f34e5acdefb1094d998fbb3074e3fa0aa94 | |
| parent | ee9f984341a3e5b52ae97573d97e20cde57ada94 (diff) | |
| download | yuescript-2fad28df04f2c8f015ccf90e16e74c47ad174bde.tar.gz yuescript-2fad28df04f2c8f015ccf90e16e74c47ad174bde.tar.bz2 yuescript-2fad28df04f2c8f015ccf90e16e74c47ad174bde.zip | |
cleanup.
Diffstat (limited to '')
| -rw-r--r-- | src/yuescript/yue_parser.cpp | 36 | ||||
| -rw-r--r-- | src/yuescript/yue_parser.h | 2 |
2 files changed, 19 insertions, 19 deletions
diff --git a/src/yuescript/yue_parser.cpp b/src/yuescript/yue_parser.cpp index e78b331..e62417c 100644 --- a/src/yuescript/yue_parser.cpp +++ b/src/yuescript/yue_parser.cpp | |||
| @@ -47,8 +47,8 @@ YueParser::YueParser() { | |||
| 47 | space = -(and_(set(" \t-\\")) >> *space_one >> -comment); | 47 | space = -(and_(set(" \t-\\")) >> *space_one >> -comment); |
| 48 | space_break = space >> line_break; | 48 | space_break = space >> line_break; |
| 49 | white = space >> *(line_break >> space); | 49 | white = space >> *(line_break >> space); |
| 50 | empty_line = space_break; | ||
| 51 | alpha_num = sel({range('a', 'z'), range('A', 'Z'), range('0', '9'), '_'}); | 50 | alpha_num = sel({range('a', 'z'), range('A', 'Z'), range('0', '9'), '_'}); |
| 51 | not_alpha_num = not_(alpha_num); | ||
| 52 | Name = sel({range('a', 'z'), range('A', 'Z'), '_'}) >> *alpha_num; | 52 | Name = sel({range('a', 'z'), range('A', 'Z'), '_'}) >> *alpha_num; |
| 53 | num_expo = set("eE") >> -set("+-") >> num_char; | 53 | num_expo = set("eE") >> -set("+-") >> num_char; |
| 54 | num_expo_hex = set("pP") >> -set("+-") >> num_char; | 54 | num_expo_hex = set("pP") >> -set("+-") >> num_char; |
| @@ -86,7 +86,7 @@ YueParser::YueParser() { | |||
| 86 | 86 | ||
| 87 | #define ensure(patt, finally) ((patt) >> (finally) | (finally) >> cut) | 87 | #define ensure(patt, finally) ((patt) >> (finally) | (finally) >> cut) |
| 88 | 88 | ||
| 89 | #define key(str) (str >> not_(alpha_num)) | 89 | #define key(str) (str >> not_alpha_num) |
| 90 | 90 | ||
| 91 | #define disable_do_rule(patt) ( \ | 91 | #define disable_do_rule(patt) ( \ |
| 92 | disable_do >> ( \ | 92 | disable_do >> ( \ |
| @@ -291,7 +291,7 @@ YueParser::YueParser() { | |||
| 291 | 291 | ||
| 292 | ShortTabAppending = "[]" >> space >> Assign; | 292 | ShortTabAppending = "[]" >> space >> Assign; |
| 293 | 293 | ||
| 294 | BreakLoop = sel({"break", "continue"}) >> not_(alpha_num); | 294 | BreakLoop = sel({"break", "continue"}) >> not_alpha_num; |
| 295 | 295 | ||
| 296 | Return = key("return") >> -(space >> (TableBlock | ExpListLow)); | 296 | Return = key("return") >> -(space >> (TableBlock | ExpListLow)); |
| 297 | 297 | ||
| @@ -302,8 +302,8 @@ YueParser::YueParser() { | |||
| 302 | switch_else = key("else") >> space >> body; | 302 | switch_else = key("else") >> space >> body; |
| 303 | 303 | ||
| 304 | switch_block = | 304 | switch_block = |
| 305 | *(line_break >> *empty_line >> check_indent_match >> space >> SwitchCase) >> | 305 | *(line_break >> *space_break >> check_indent_match >> space >> SwitchCase) >> |
| 306 | -(line_break >> *empty_line >> check_indent_match >> space >> switch_else); | 306 | -(line_break >> *space_break >> check_indent_match >> space >> switch_else); |
| 307 | 307 | ||
| 308 | exp_not_tab = not_(SimpleTable | TableLit) >> space >> Exp; | 308 | exp_not_tab = not_(SimpleTable | TableLit) >> space >> Exp; |
| 309 | 309 | ||
| @@ -314,22 +314,22 @@ YueParser::YueParser() { | |||
| 314 | Switch = key("switch") >> space >> Exp >> | 314 | Switch = key("switch") >> space >> Exp >> |
| 315 | space >> Seperator >> ( | 315 | space >> Seperator >> ( |
| 316 | SwitchCase >> space >> ( | 316 | SwitchCase >> space >> ( |
| 317 | line_break >> *empty_line >> check_indent_match >> space >> SwitchCase >> switch_block | | 317 | line_break >> *space_break >> check_indent_match >> space >> SwitchCase >> switch_block | |
| 318 | *(space >> SwitchCase) >> -(space >> switch_else) | 318 | *(space >> SwitchCase) >> -(space >> switch_else) |
| 319 | ) | | 319 | ) | |
| 320 | space_break >> *empty_line >> advance_match >> space >> SwitchCase >> switch_block >> pop_indent | 320 | +space_break >> advance_match >> space >> SwitchCase >> switch_block >> pop_indent |
| 321 | ) >> switch_block; | 321 | ) >> switch_block; |
| 322 | 322 | ||
| 323 | Assignment = ExpList >> space >> Assign; | 323 | Assignment = ExpList >> space >> Assign; |
| 324 | IfCond = disable_chain_rule(disable_arg_table_block_rule(Assignment | Exp)); | 324 | IfCond = disable_chain_rule(disable_arg_table_block_rule(Assignment | Exp)); |
| 325 | if_else_if = -(line_break >> *empty_line >> check_indent_match) >> space >> key("elseif") >> space >> IfCond >> space >> body_with("then"); | 325 | if_else_if = -(line_break >> *space_break >> check_indent_match) >> space >> key("elseif") >> space >> IfCond >> space >> body_with("then"); |
| 326 | if_else = -(line_break >> *empty_line >> check_indent_match) >> space >> key("else") >> space >> body; | 326 | if_else = -(line_break >> *space_break >> check_indent_match) >> space >> key("else") >> space >> body; |
| 327 | IfType = sel({"if", "unless"}) >> not_(alpha_num); | 327 | IfType = sel({"if", "unless"}) >> not_alpha_num; |
| 328 | If = seq({IfType, space, IfCond, space, opt_body_with("then"), *if_else_if, -if_else}); | 328 | If = seq({IfType, space, IfCond, space, opt_body_with("then"), *if_else_if, -if_else}); |
| 329 | 329 | ||
| 330 | WhileType = sel({"while", "until"}) >> not_(alpha_num); | 330 | WhileType = sel({"while", "until"}) >> not_alpha_num; |
| 331 | While = WhileType >> space >> disable_do_chain_arg_table_block_rule(Exp) >> space >> opt_body_with("do"); | 331 | While = WhileType >> space >> disable_do_chain_arg_table_block_rule(Exp) >> space >> opt_body_with("do"); |
| 332 | Repeat = seq({key("repeat"), space, Body, line_break, *empty_line, check_indent_match, space, key("until"), space, Exp}); | 332 | Repeat = seq({key("repeat"), space, Body, line_break, *space_break, check_indent_match, space, key("until"), space, Exp}); |
| 333 | 333 | ||
| 334 | ForStepValue = ',' >> space >> Exp; | 334 | ForStepValue = ',' >> space >> Exp; |
| 335 | for_args = Variable >> space >> '=' >> space >> Exp >> space >> ',' >> space >> Exp >> space >> -ForStepValue; | 335 | for_args = Variable >> space >> '=' >> space >> Exp >> space >> ',' >> space >> Exp >> space >> -ForStepValue; |
| @@ -386,7 +386,7 @@ YueParser::YueParser() { | |||
| 386 | return true; | 386 | return true; |
| 387 | }); | 387 | }); |
| 388 | 388 | ||
| 389 | CatchBlock = line_break >> *empty_line >> check_indent_match >> space >> key("catch") >> space >> Variable >> space >> in_block; | 389 | CatchBlock = line_break >> *space_break >> check_indent_match >> space >> key("catch") >> space >> Variable >> space >> in_block; |
| 390 | Try = key("try") >> space >> (in_block | Exp) >> -CatchBlock; | 390 | Try = key("try") >> space >> (in_block | Exp) >> -CatchBlock; |
| 391 | 391 | ||
| 392 | Comprehension = '[' >> not_('[') >> space >> Exp >> space >> CompInner >> space >> ']'; | 392 | Comprehension = '[' >> not_('[') >> space >> Exp >> space >> CompInner >> space >> ']'; |
| @@ -424,7 +424,7 @@ YueParser::YueParser() { | |||
| 424 | '-' >> not_(set(">=") | space_one), | 424 | '-' >> not_(set(">=") | space_one), |
| 425 | '#', | 425 | '#', |
| 426 | '~' >> not_('=' | space_one), | 426 | '~' >> not_('=' | space_one), |
| 427 | "not" >> not_(alpha_num) | 427 | "not" >> not_alpha_num |
| 428 | }); | 428 | }); |
| 429 | UnaryExp = *(UnaryOperator >> space) >> expo_exp; | 429 | UnaryExp = *(UnaryOperator >> space) >> expo_exp; |
| 430 | 430 | ||
| @@ -433,8 +433,8 @@ YueParser::YueParser() { | |||
| 433 | pipe_exp = UnaryExp >> *(space >> pipe_value); | 433 | pipe_exp = UnaryExp >> *(space >> pipe_value); |
| 434 | 434 | ||
| 435 | BinaryOperator = sel({ | 435 | BinaryOperator = sel({ |
| 436 | "or" >> not_(alpha_num), | 436 | "or" >> not_alpha_num, |
| 437 | "and" >> not_(alpha_num), | 437 | "and" >> not_alpha_num, |
| 438 | "<=", ">=", "~=", "!=", "==", | 438 | "<=", ">=", "~=", "!=", "==", |
| 439 | "..", "<<", ">>", "//", | 439 | "..", "<<", ">>", "//", |
| 440 | set("+-*/%><|&~") | 440 | set("+-*/%><|&~") |
| @@ -595,7 +595,7 @@ YueParser::YueParser() { | |||
| 595 | white, '}' | 595 | white, '}' |
| 596 | }); | 596 | }); |
| 597 | 597 | ||
| 598 | table_value_list = table_value >> *(space >> ',' >> space >> table_value); | 598 | table_value_list = table_value >> *seq({space, ',', space, table_value}); |
| 599 | 599 | ||
| 600 | table_lit_line = ( | 600 | table_lit_line = ( |
| 601 | push_indent_match >> (space >> table_value_list >> pop_indent | pop_indent) | 601 | push_indent_match >> (space >> table_value_list >> pop_indent | pop_indent) |
| @@ -762,7 +762,7 @@ YueParser::YueParser() { | |||
| 762 | leading_spaces_error | 762 | leading_spaces_error |
| 763 | }); | 763 | }); |
| 764 | 764 | ||
| 765 | ConstValue = sel({"nil", "true", "false"}) >> not_(alpha_num); | 765 | ConstValue = sel({"nil", "true", "false"}) >> not_alpha_num; |
| 766 | 766 | ||
| 767 | SimpleValue = sel({ | 767 | SimpleValue = sel({ |
| 768 | TableLit, ConstValue, If, Switch, Try, With, | 768 | TableLit, ConstValue, If, Switch, Try, With, |
diff --git a/src/yuescript/yue_parser.h b/src/yuescript/yue_parser.h index e98b711..f3b3f4f 100644 --- a/src/yuescript/yue_parser.h +++ b/src/yuescript/yue_parser.h | |||
| @@ -140,8 +140,8 @@ private: | |||
| 140 | rule space_one; | 140 | rule space_one; |
| 141 | rule space; | 141 | rule space; |
| 142 | rule space_break; | 142 | rule space_break; |
| 143 | rule empty_line; | ||
| 144 | rule alpha_num; | 143 | rule alpha_num; |
| 144 | rule not_alpha_num; | ||
| 145 | rule cut; | 145 | rule cut; |
| 146 | rule check_indent_match; | 146 | rule check_indent_match; |
| 147 | rule check_indent; | 147 | rule check_indent; |
