From 05ef9bb1ffefbc717f3fb4738f3683b3cb09a82e Mon Sep 17 00:00:00 2001 From: Li Jin Date: Fri, 17 Dec 2021 17:33:38 +0800 Subject: eliminate some ambiguous syntax. --- spec/inputs/cond.yue | 16 ++++++++++++++++ spec/outputs/cond.lua | 30 ++++++++++++++++++++++++++++++ src/yuescript/yue_compiler.cpp | 2 +- src/yuescript/yue_parser.cpp | 2 +- 4 files changed, 48 insertions(+), 2 deletions(-) diff --git a/spec/inputs/cond.yue b/spec/inputs/cond.yue index 3dee99b..d33eec4 100644 --- a/spec/inputs/cond.yue +++ b/spec/inputs/cond.yue @@ -182,7 +182,23 @@ m = if 1 else 6 +do + a + :b + return if a + :b + else if c + d: e + else + f: 123 +do + c + d: e + if a + :b = tb + elseif c + d: e = tb nil diff --git a/spec/outputs/cond.lua b/spec/outputs/cond.lua index 5efa237..8f69e97 100644 --- a/spec/outputs/cond.lua +++ b/spec/outputs/cond.lua @@ -269,4 +269,34 @@ if 1 then else m = 6 end +do + a({ + b = b + }) + if a then + return { + b = b + } + else + if c then + return { + d = e + } + else + return { + f = 123 + } + end + end +end +do + c({ + d = e + }) + if a then + b = tb.b + elseif c then + local e = tb.d + end +end return nil diff --git a/src/yuescript/yue_compiler.cpp b/src/yuescript/yue_compiler.cpp index 15a785a..6295eb7 100755 --- a/src/yuescript/yue_compiler.cpp +++ b/src/yuescript/yue_compiler.cpp @@ -60,7 +60,7 @@ using namespace parserlib; typedef std::list str_list; -const std::string_view version = "0.9.4"sv; +const std::string_view version = "0.9.5"sv; const std::string_view extension = "yue"sv; class YueCompilerImpl { diff --git a/src/yuescript/yue_parser.cpp b/src/yuescript/yue_parser.cpp index 9257fab..03639c3 100755 --- a/src/yuescript/yue_parser.cpp +++ b/src/yuescript/yue_parser.cpp @@ -236,7 +236,7 @@ YueParser::YueParser() { Switch = Space >> key("switch") >> disable_do(Exp) >> -(Space >> key("do")) >> -Space >> Break >> SwitchBlock; - IfCond = disable_chain(Exp >> -Assign); + IfCond = disable_do_chain(disable_arg_table_block(Exp >> -Assign)); IfElseIf = -(Break >> *EmptyLine >> CheckIndent) >> Space >> key("elseif") >> IfCond >> plain_body_with("then"); IfElse = -(Break >> *EmptyLine >> CheckIndent) >> Space >> key("else") >> plain_body; IfType = (expr("if") | expr("unless")) >> not_(AlphaNum); -- cgit v1.2.3-55-g6feb