From ed317e62eb1cf98fde4461fc90c6cb1045ebc7e8 Mon Sep 17 00:00:00 2001 From: Li Jin Date: Sat, 25 Jan 2020 17:48:03 +0800 Subject: fix Moonscript issue 375. --- src/MoonP/moon_ast.h | 3 ++- src/MoonP/moon_compiler.cpp | 1 + src/MoonP/moon_parser.cpp | 4 ++-- 3 files changed, 5 insertions(+), 3 deletions(-) (limited to 'src') 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) AST_NODE(if_else_line, "if_else_line"_id) ast_ptr condition; + ast_ptr assign; ast_sel elseExpr; - AST_MEMBER(if_else_line, &condition, &elseExpr) + AST_MEMBER(if_else_line, &condition, &assign, &elseExpr) AST_END(if_else_line) 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: auto ifCond = x->new_ptr(); ifCond->condition.set(if_else_line->condition); + ifCond->assign.set(if_else_line->assign); ifNode->nodes.push_back(ifCond); auto stmt = x->new_ptr(); 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; rule IfElseIf = -(Break >> *EmptyLine >> CheckIndent) >> key("elseif") >> IfCond >> -key("then") >> Body; rule IfElse = -(Break >> *EmptyLine >> CheckIndent) >> key("else") >> Body; rule If = key("if") >> Seperator >> IfCond >> -key("then") >> Body >> *IfElseIf >> -IfElse; -rule Unless = key("unless") >> Seperator >> IfCond >> -key("then") >> Body >> *IfElseIf >> -IfElse; +rule Unless = key("unless") >> Seperator >> IfCond >> -key("then") >> Body >> *IfElseIf >> -IfElse; rule While = key("while") >> DisableDo >> ensure(Exp, PopDo) >> -key("do") >> Body; @@ -510,7 +510,7 @@ rule SimpleValue = rule ExpListAssign = ExpList >> -(Update | Assign); -rule if_else_line = key("if") >> Exp >> (key("else") >> Exp | default_value); +rule if_else_line = key("if") >> Exp >> -Assign >> (key("else") >> Exp | default_value); rule unless_line = key("unless") >> Exp; rule statement_appendix = (if_else_line | unless_line | CompInner) >> Space; -- cgit v1.2.3-55-g6feb