diff options
author | Li Jin <dragon-fly@qq.com> | 2020-01-25 17:48:03 +0800 |
---|---|---|
committer | Li Jin <dragon-fly@qq.com> | 2020-01-25 17:48:03 +0800 |
commit | ed317e62eb1cf98fde4461fc90c6cb1045ebc7e8 (patch) | |
tree | 427e365939da39f31dbfa755675fb60bb141583d /src | |
parent | 4827d200604a086e2ad94edb4257c3abc7a3c4fc (diff) | |
download | yuescript-ed317e62eb1cf98fde4461fc90c6cb1045ebc7e8.tar.gz yuescript-ed317e62eb1cf98fde4461fc90c6cb1045ebc7e8.tar.bz2 yuescript-ed317e62eb1cf98fde4461fc90c6cb1045ebc7e8.zip |
fix Moonscript issue 375.
Diffstat (limited to 'src')
-rw-r--r-- | src/MoonP/moon_ast.h | 3 | ||||
-rw-r--r-- | src/MoonP/moon_compiler.cpp | 1 | ||||
-rw-r--r-- | src/MoonP/moon_parser.cpp | 4 |
3 files changed, 5 insertions, 3 deletions
diff --git a/src/MoonP/moon_ast.h b/src/MoonP/moon_ast.h index f8d2099..e71afe9 100644 --- a/src/MoonP/moon_ast.h +++ b/src/MoonP/moon_ast.h | |||
@@ -565,8 +565,9 @@ AST_END(ExpListAssign) | |||
565 | 565 | ||
566 | AST_NODE(if_else_line, "if_else_line"_id) | 566 | AST_NODE(if_else_line, "if_else_line"_id) |
567 | ast_ptr<true, Exp_t> condition; | 567 | ast_ptr<true, Exp_t> condition; |
568 | ast_ptr<false, Assign_t> assign; | ||
568 | ast_sel<false, Exp_t, default_value_t> elseExpr; | 569 | ast_sel<false, Exp_t, default_value_t> elseExpr; |
569 | AST_MEMBER(if_else_line, &condition, &elseExpr) | 570 | AST_MEMBER(if_else_line, &condition, &assign, &elseExpr) |
570 | AST_END(if_else_line) | 571 | AST_END(if_else_line) |
571 | 572 | ||
572 | AST_NODE(unless_line, "unless_line"_id) | 573 | AST_NODE(unless_line, "unless_line"_id) |
diff --git a/src/MoonP/moon_compiler.cpp b/src/MoonP/moon_compiler.cpp index b1770fb..4723af4 100644 --- a/src/MoonP/moon_compiler.cpp +++ b/src/MoonP/moon_compiler.cpp | |||
@@ -601,6 +601,7 @@ private: | |||
601 | 601 | ||
602 | auto ifCond = x->new_ptr<IfCond_t>(); | 602 | auto ifCond = x->new_ptr<IfCond_t>(); |
603 | ifCond->condition.set(if_else_line->condition); | 603 | ifCond->condition.set(if_else_line->condition); |
604 | ifCond->assign.set(if_else_line->assign); | ||
604 | ifNode->nodes.push_back(ifCond); | 605 | ifNode->nodes.push_back(ifCond); |
605 | 606 | ||
606 | auto stmt = x->new_ptr<Statement_t>(); | 607 | auto stmt = x->new_ptr<Statement_t>(); |
diff --git a/src/MoonP/moon_parser.cpp b/src/MoonP/moon_parser.cpp index d3c0ed2..6d1b86c 100644 --- a/src/MoonP/moon_parser.cpp +++ b/src/MoonP/moon_parser.cpp | |||
@@ -198,7 +198,7 @@ rule IfCond = Exp >> -Assign; | |||
198 | rule IfElseIf = -(Break >> *EmptyLine >> CheckIndent) >> key("elseif") >> IfCond >> -key("then") >> Body; | 198 | rule IfElseIf = -(Break >> *EmptyLine >> CheckIndent) >> key("elseif") >> IfCond >> -key("then") >> Body; |
199 | rule IfElse = -(Break >> *EmptyLine >> CheckIndent) >> key("else") >> Body; | 199 | rule IfElse = -(Break >> *EmptyLine >> CheckIndent) >> key("else") >> Body; |
200 | rule If = key("if") >> Seperator >> IfCond >> -key("then") >> Body >> *IfElseIf >> -IfElse; | 200 | rule If = key("if") >> Seperator >> IfCond >> -key("then") >> Body >> *IfElseIf >> -IfElse; |
201 | rule Unless = key("unless") >> Seperator >> IfCond >> -key("then") >> Body >> *IfElseIf >> -IfElse; | 201 | rule Unless = key("unless") >> Seperator >> IfCond >> -key("then") >> Body >> *IfElseIf >> -IfElse; |
202 | 202 | ||
203 | rule While = key("while") >> DisableDo >> ensure(Exp, PopDo) >> -key("do") >> Body; | 203 | rule While = key("while") >> DisableDo >> ensure(Exp, PopDo) >> -key("do") >> Body; |
204 | 204 | ||
@@ -510,7 +510,7 @@ rule SimpleValue = | |||
510 | 510 | ||
511 | rule ExpListAssign = ExpList >> -(Update | Assign); | 511 | rule ExpListAssign = ExpList >> -(Update | Assign); |
512 | 512 | ||
513 | rule if_else_line = key("if") >> Exp >> (key("else") >> Exp | default_value); | 513 | rule if_else_line = key("if") >> Exp >> -Assign >> (key("else") >> Exp | default_value); |
514 | rule unless_line = key("unless") >> Exp; | 514 | rule unless_line = key("unless") >> Exp; |
515 | 515 | ||
516 | rule statement_appendix = (if_else_line | unless_line | CompInner) >> Space; | 516 | rule statement_appendix = (if_else_line | unless_line | CompInner) >> Space; |