diff options
author | Li Jin <dragon-fly@qq.com> | 2020-03-26 16:21:30 +0800 |
---|---|---|
committer | Li Jin <dragon-fly@qq.com> | 2020-03-26 16:21:30 +0800 |
commit | 69091011685db34e5dc4012e9d2cf24a0ac77715 (patch) | |
tree | b948a213f4044c105c9baf674e077d210ae60024 | |
parent | a97ca224f23b4101e44c099dbe29d1cc4a72c758 (diff) | |
download | yuescript-69091011685db34e5dc4012e9d2cf24a0ac77715.tar.gz yuescript-69091011685db34e5dc4012e9d2cf24a0ac77715.tar.bz2 yuescript-69091011685db34e5dc4012e9d2cf24a0ac77715.zip |
remove else branch support for appendix syntax.
-rw-r--r-- | spec/inputs/syntax.moon | 2 | ||||
-rw-r--r-- | src/MoonP/moon_ast.h | 9 | ||||
-rw-r--r-- | src/MoonP/moon_compiler.cpp | 22 | ||||
-rw-r--r-- | src/MoonP/moon_parser.cpp | 4 | ||||
-rw-r--r-- | src/MoonP/moon_parser.h | 2 |
5 files changed, 13 insertions, 26 deletions
diff --git a/spec/inputs/syntax.moon b/spec/inputs/syntax.moon index 5442b61..b5f973b 100644 --- a/spec/inputs/syntax.moon +++ b/spec/inputs/syntax.moon | |||
@@ -122,7 +122,7 @@ print "nutjob" | |||
122 | 122 | ||
123 | if hello then _ = 343 | 123 | if hello then _ = 343 |
124 | 124 | ||
125 | print "what" if cool else whack! | 125 | print "what" if cool |
126 | 126 | ||
127 | arg = {...} | 127 | arg = {...} |
128 | 128 | ||
diff --git a/src/MoonP/moon_ast.h b/src/MoonP/moon_ast.h index 3f9ce79..0743014 100644 --- a/src/MoonP/moon_ast.h +++ b/src/MoonP/moon_ast.h | |||
@@ -642,12 +642,11 @@ AST_NODE(ExpListAssign) | |||
642 | AST_MEMBER(ExpListAssign, &expList, &action) | 642 | AST_MEMBER(ExpListAssign, &expList, &action) |
643 | AST_END(ExpListAssign) | 643 | AST_END(ExpListAssign) |
644 | 644 | ||
645 | AST_NODE(if_else_line) | 645 | AST_NODE(if_line) |
646 | ast_ptr<true, Exp_t> condition; | 646 | ast_ptr<true, Exp_t> condition; |
647 | ast_ptr<false, Assign_t> assign; | 647 | ast_ptr<false, Assign_t> assign; |
648 | ast_sel<false, Exp_t, default_value_t> elseExpr; | 648 | AST_MEMBER(if_line, &condition, &assign) |
649 | AST_MEMBER(if_else_line, &condition, &assign, &elseExpr) | 649 | AST_END(if_line) |
650 | AST_END(if_else_line) | ||
651 | 650 | ||
652 | AST_NODE(unless_line) | 651 | AST_NODE(unless_line) |
653 | ast_ptr<true, Exp_t> condition; | 652 | ast_ptr<true, Exp_t> condition; |
@@ -655,7 +654,7 @@ AST_NODE(unless_line) | |||
655 | AST_END(unless_line) | 654 | AST_END(unless_line) |
656 | 655 | ||
657 | AST_NODE(statement_appendix) | 656 | AST_NODE(statement_appendix) |
658 | ast_sel<true, if_else_line_t, unless_line_t, CompInner_t> item; | 657 | ast_sel<true, if_line_t, unless_line_t, CompInner_t> item; |
659 | AST_MEMBER(statement_appendix, &item) | 658 | AST_MEMBER(statement_appendix, &item) |
660 | AST_END(statement_appendix) | 659 | AST_END(statement_appendix) |
661 | 660 | ||
diff --git a/src/MoonP/moon_compiler.cpp b/src/MoonP/moon_compiler.cpp index b89f6d1..e961a92 100644 --- a/src/MoonP/moon_compiler.cpp +++ b/src/MoonP/moon_compiler.cpp | |||
@@ -43,7 +43,7 @@ inline std::string s(std::string_view sv) { | |||
43 | } | 43 | } |
44 | 44 | ||
45 | const char* moonScriptVersion() { | 45 | const char* moonScriptVersion() { |
46 | return "0.5.0-r0.3.5"; | 46 | return "0.5.0-r0.3.6"; |
47 | } | 47 | } |
48 | 48 | ||
49 | // name of table stored in lua registry | 49 | // name of table stored in lua registry |
@@ -641,13 +641,13 @@ private: | |||
641 | } | 641 | } |
642 | auto appendix = statement->appendix.get(); | 642 | auto appendix = statement->appendix.get(); |
643 | switch (appendix->item->getId()) { | 643 | switch (appendix->item->getId()) { |
644 | case id<if_else_line_t>(): { | 644 | case id<if_line_t>(): { |
645 | auto if_else_line = appendix->item.to<if_else_line_t>(); | 645 | auto if_line = appendix->item.to<if_line_t>(); |
646 | auto ifNode = x->new_ptr<If_t>(); | 646 | auto ifNode = x->new_ptr<If_t>(); |
647 | 647 | ||
648 | auto ifCond = x->new_ptr<IfCond_t>(); | 648 | auto ifCond = x->new_ptr<IfCond_t>(); |
649 | ifCond->condition.set(if_else_line->condition); | 649 | ifCond->condition.set(if_line->condition); |
650 | ifCond->assign.set(if_else_line->assign); | 650 | ifCond->assign.set(if_line->assign); |
651 | ifNode->nodes.push_back(ifCond); | 651 | ifNode->nodes.push_back(ifCond); |
652 | 652 | ||
653 | auto stmt = x->new_ptr<Statement_t>(); | 653 | auto stmt = x->new_ptr<Statement_t>(); |
@@ -656,18 +656,6 @@ private: | |||
656 | body->content.set(stmt); | 656 | body->content.set(stmt); |
657 | ifNode->nodes.push_back(body); | 657 | ifNode->nodes.push_back(body); |
658 | 658 | ||
659 | if (!ast_is<default_value_t>(if_else_line->elseExpr)) { | ||
660 | auto expList = x->new_ptr<ExpList_t>(); | ||
661 | expList->exprs.push_back(if_else_line->elseExpr); | ||
662 | auto expListAssign = x->new_ptr<ExpListAssign_t>(); | ||
663 | expListAssign->expList.set(expList); | ||
664 | auto stmt = x->new_ptr<Statement_t>(); | ||
665 | stmt->content.set(expListAssign); | ||
666 | auto body = x->new_ptr<Body_t>(); | ||
667 | body->content.set(stmt); | ||
668 | ifNode->nodes.push_back(body); | ||
669 | } | ||
670 | |||
671 | statement->appendix.set(nullptr); | 659 | statement->appendix.set(nullptr); |
672 | auto simpleValue = x->new_ptr<SimpleValue_t>(); | 660 | auto simpleValue = x->new_ptr<SimpleValue_t>(); |
673 | simpleValue->value.set(ifNode); | 661 | simpleValue->value.set(ifNode); |
diff --git a/src/MoonP/moon_parser.cpp b/src/MoonP/moon_parser.cpp index 58f8fb3..9208d3a 100644 --- a/src/MoonP/moon_parser.cpp +++ b/src/MoonP/moon_parser.cpp | |||
@@ -533,10 +533,10 @@ MoonParser::MoonParser() { | |||
533 | 533 | ||
534 | ExpListAssign = ExpList >> -(Update | Assign); | 534 | ExpListAssign = ExpList >> -(Update | Assign); |
535 | 535 | ||
536 | if_else_line = key("if") >> Exp >> -Assign >> (key("else") >> Exp | default_value); | 536 | if_line = key("if") >> Exp >> -Assign; |
537 | unless_line = key("unless") >> Exp; | 537 | unless_line = key("unless") >> Exp; |
538 | 538 | ||
539 | statement_appendix = (if_else_line | unless_line | CompInner) >> Space; | 539 | statement_appendix = (if_line | unless_line | CompInner) >> Space; |
540 | Statement = ( | 540 | Statement = ( |
541 | Import | While | For | ForEach | | 541 | Import | While | For | ForEach | |
542 | Return | Local | Global | Export | | 542 | Return | Local | Global | Export | |
diff --git a/src/MoonP/moon_parser.h b/src/MoonP/moon_parser.h index cea14fa..ec51340 100644 --- a/src/MoonP/moon_parser.h +++ b/src/MoonP/moon_parser.h | |||
@@ -286,7 +286,7 @@ private: | |||
286 | AST_RULE(const_value) | 286 | AST_RULE(const_value) |
287 | AST_RULE(unary_exp) | 287 | AST_RULE(unary_exp) |
288 | AST_RULE(ExpListAssign) | 288 | AST_RULE(ExpListAssign) |
289 | AST_RULE(if_else_line) | 289 | AST_RULE(if_line) |
290 | AST_RULE(unless_line) | 290 | AST_RULE(unless_line) |
291 | AST_RULE(statement_appendix) | 291 | AST_RULE(statement_appendix) |
292 | AST_RULE(BreakLoop) | 292 | AST_RULE(BreakLoop) |