diff options
author | Li Jin <dragon-fly@qq.com> | 2020-05-29 02:00:20 +0800 |
---|---|---|
committer | Li Jin <dragon-fly@qq.com> | 2020-05-29 02:00:20 +0800 |
commit | 88c1052e700f38cf3d8ad82d469da4c487760b7e (patch) | |
tree | aaa19c10ea1f9653e249b529586a688c275563ca /src/MoonP/moon_parser.cpp | |
parent | 04e3cd43cee426cd5c2fa1d0fab5fabc7f19c039 (diff) | |
download | yuescript-88c1052e700f38cf3d8ad82d469da4c487760b7e.tar.gz yuescript-88c1052e700f38cf3d8ad82d469da4c487760b7e.tar.bz2 yuescript-88c1052e700f38cf3d8ad82d469da4c487760b7e.zip |
change operator precedence to [1].^ [2].unary operators (not, #, -, ~) [3].|> [4].*, /, //, %, ...
fix destructure with one table variable to operator-value expression.
fix simple chain value with Lua keyword colon chain item.
Diffstat (limited to 'src/MoonP/moon_parser.cpp')
-rw-r--r-- | src/MoonP/moon_parser.cpp | 37 |
1 files changed, 23 insertions, 14 deletions
diff --git a/src/MoonP/moon_parser.cpp b/src/MoonP/moon_parser.cpp index 2d71567..25e67b3 100644 --- a/src/MoonP/moon_parser.cpp +++ b/src/MoonP/moon_parser.cpp | |||
@@ -292,6 +292,25 @@ MoonParser::MoonParser() { | |||
292 | 292 | ||
293 | Update = Space >> update_op >> expr("=") >> Exp; | 293 | Update = Space >> update_op >> expr("=") >> Exp; |
294 | 294 | ||
295 | Assignable = AssignableChain | Space >> Variable | Space >> SelfName; | ||
296 | |||
297 | unary_value = unary_operator >> *(Space >> unary_operator) >> Value; | ||
298 | |||
299 | ExponentialOperator = expr('^'); | ||
300 | expo_value = Space >> ExponentialOperator >> *SpaceBreak >> Value; | ||
301 | expo_exp = Value >> *expo_value; | ||
302 | |||
303 | unary_operator = | ||
304 | expr('-') >> not_(expr('>') | space_one) | | ||
305 | expr('#') | | ||
306 | expr('~') >> not_(space_one) | | ||
307 | expr("not") >> not_(AlphaNum); | ||
308 | unary_exp = *(Space >> unary_operator) >> expo_exp; | ||
309 | |||
310 | BackcallOperator = expr("|>"); | ||
311 | backcall_value = Space >> BackcallOperator >> *SpaceBreak >> unary_exp; | ||
312 | backcall_exp = unary_exp >> *backcall_value; | ||
313 | |||
295 | BinaryOperator = | 314 | BinaryOperator = |
296 | (expr("or") >> not_(AlphaNum)) | | 315 | (expr("or") >> not_(AlphaNum)) | |
297 | (expr("and") >> not_(AlphaNum)) | | 316 | (expr("and") >> not_(AlphaNum)) | |
@@ -304,14 +323,9 @@ MoonParser::MoonParser() { | |||
304 | expr("<<") | | 323 | expr("<<") | |
305 | expr(">>") | | 324 | expr(">>") | |
306 | expr("//") | | 325 | expr("//") | |
307 | set("+-*/%^><|&~"); | 326 | set("+-*/%><|&~"); |
308 | 327 | exp_op_value = Space >> BinaryOperator >> *SpaceBreak >> backcall_exp; | |
309 | BackcallOperator = expr("|>"); | 328 | Exp = Seperator >> backcall_exp >> *exp_op_value; |
310 | |||
311 | Assignable = AssignableChain | Space >> Variable | Space >> SelfName; | ||
312 | |||
313 | exp_op_value = Space >> (BackcallOperator | BinaryOperator) >> *SpaceBreak >> Value; | ||
314 | Exp = Value >> *exp_op_value; | ||
315 | 329 | ||
316 | ChainValue = Seperator >> (Chain | Callable) >> -existential_op >> -InvokeArgs; | 330 | ChainValue = Seperator >> (Chain | Callable) >> -existential_op >> -InvokeArgs; |
317 | 331 | ||
@@ -520,16 +534,11 @@ MoonParser::MoonParser() { | |||
520 | ); | 534 | ); |
521 | 535 | ||
522 | const_value = (expr("nil") | expr("true") | expr("false")) >> not_(AlphaNum); | 536 | const_value = (expr("nil") | expr("true") | expr("false")) >> not_(AlphaNum); |
523 | minus_exp = expr('-') >> not_(space_one) >> Exp; | ||
524 | sharp_exp = expr('#') >> Exp; | ||
525 | tilde_exp = expr('~') >> not_(space_one) >> Exp; | ||
526 | not_exp = expr("not") >> not_(AlphaNum) >> Exp; | ||
527 | unary_exp = minus_exp | sharp_exp | tilde_exp | not_exp; | ||
528 | 537 | ||
529 | SimpleValue = | 538 | SimpleValue = |
530 | (Space >> const_value) | | 539 | (Space >> const_value) | |
531 | If | Unless | Switch | With | ClassDecl | ForEach | For | While | Do | | 540 | If | Unless | Switch | With | ClassDecl | ForEach | For | While | Do | |
532 | (Space >> unary_exp) | | 541 | (Space >> unary_value) | |
533 | TblComprehension | TableLit | Comprehension | FunLit | | 542 | TblComprehension | TableLit | Comprehension | FunLit | |
534 | (Space >> Num); | 543 | (Space >> Num); |
535 | 544 | ||