From 7de25e2ef75a748356c79d0015a5d934dde4c216 Mon Sep 17 00:00:00 2001 From: Li Jin Date: Tue, 19 Dec 2023 23:29:07 +0800 Subject: fix a const list destructuring case. --- spec/inputs/attrib.yue | 3 +++ spec/outputs/5.1/attrib.lua | 10 ++++++++++ spec/outputs/attrib.lua | 10 ++++++++++ src/yuescript/yue_ast.h | 3 ++- src/yuescript/yue_compiler.cpp | 5 +++-- src/yuescript/yue_parser.cpp | 2 +- 6 files changed, 29 insertions(+), 4 deletions(-) diff --git a/spec/inputs/attrib.yue b/spec/inputs/attrib.yue index fbff75a..36aca99 100644 --- a/spec/inputs/attrib.yue +++ b/spec/inputs/attrib.yue @@ -13,6 +13,9 @@ do do const a, {b, c}, {d} = f! +do + const [a, b] = [2, 3] + do close v = if flag func! diff --git a/spec/outputs/5.1/attrib.lua b/spec/outputs/5.1/attrib.lua index f782b45..70e7e24 100644 --- a/spec/outputs/5.1/attrib.lua +++ b/spec/outputs/5.1/attrib.lua @@ -40,6 +40,16 @@ do d = _obj_2[1] end end +do + local a, b + do + local _obj_0 = { + 2, + 3 + } + a, b = _obj_0[1], _obj_0[2] + end +end do local v = (function() if flag then diff --git a/spec/outputs/attrib.lua b/spec/outputs/attrib.lua index 919b7e0..181555f 100644 --- a/spec/outputs/attrib.lua +++ b/spec/outputs/attrib.lua @@ -29,6 +29,16 @@ do d = _obj_2[1] end end +do + local a, b + do + local _obj_0 = { + 2, + 3 + } + a, b = _obj_0[1], _obj_0[2] + end +end do local v = (function() if flag then diff --git a/src/yuescript/yue_ast.h b/src/yuescript/yue_ast.h index 6b2b7f8..6d90add 100644 --- a/src/yuescript/yue_ast.h +++ b/src/yuescript/yue_ast.h @@ -80,6 +80,7 @@ class Macro_t; class In_t; class NormalDef_t; class SpreadListExp_t; +class Comprehension_t; } // namespace yue AST_LEAF(Num) @@ -171,7 +172,7 @@ AST_END(CloseAttrib, "close"sv) AST_NODE(LocalAttrib) ast_sel attrib; ast_ptr sep; - ast_sel_list leftList; + ast_sel_list leftList; ast_ptr assign; AST_MEMBER(LocalAttrib, &attrib, &sep, &leftList, &assign) AST_END(LocalAttrib, "local_attrib"sv) diff --git a/src/yuescript/yue_compiler.cpp b/src/yuescript/yue_compiler.cpp index d43f79b..f163bdf 100644 --- a/src/yuescript/yue_compiler.cpp +++ b/src/yuescript/yue_compiler.cpp @@ -75,7 +75,7 @@ static std::unordered_set Metamethods = { "close"s // Lua 5.4 }; -const std::string_view version = "0.21.5"sv; +const std::string_view version = "0.21.6"sv; const std::string_view extension = "yue"sv; class CompileError : public std::logic_error { @@ -9376,7 +9376,8 @@ private: case id(): value->item.set(item); break; - case id(): { + case id(): + case id(): { auto simpleValue = item->new_ptr(); simpleValue->value.set(item); value->item.set(simpleValue); diff --git a/src/yuescript/yue_parser.cpp b/src/yuescript/yue_parser.cpp index 3557534..4e6105b 100644 --- a/src/yuescript/yue_parser.cpp +++ b/src/yuescript/yue_parser.cpp @@ -286,7 +286,7 @@ YueParser::YueParser() { ConstAttrib = key("const"); CloseAttrib = key("close"); - local_const_item = Variable | SimpleTable | TableLit; + local_const_item = Variable | SimpleTable | TableLit | Comprehension; LocalAttrib = ( ConstAttrib >> Seperator >> space >> local_const_item >> *(space >> ',' >> space >> local_const_item) | CloseAttrib >> Seperator >> space >> Variable >> *(space >> ',' >> space >> Variable) -- cgit v1.2.3-55-g6feb