aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--spec/inputs/attrib.yue3
-rw-r--r--spec/outputs/5.1/attrib.lua10
-rw-r--r--spec/outputs/attrib.lua10
-rw-r--r--src/yuescript/yue_ast.h3
-rw-r--r--src/yuescript/yue_compiler.cpp5
-rw-r--r--src/yuescript/yue_parser.cpp2
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
@@ -14,6 +14,9 @@ do
14 const a, {b, c}, {d} = f! 14 const a, {b, c}, {d} = f!
15 15
16do 16do
17 const [a, b] = [2, 3]
18
19do
17 close v = if flag 20 close v = if flag
18 func! 21 func!
19 else 22 else
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
@@ -41,6 +41,16 @@ do
41 end 41 end
42end 42end
43do 43do
44 local a, b
45 do
46 local _obj_0 = {
47 2,
48 3
49 }
50 a, b = _obj_0[1], _obj_0[2]
51 end
52end
53do
44 local v = (function() 54 local v = (function()
45 if flag then 55 if flag then
46 return func() 56 return func()
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
@@ -30,6 +30,16 @@ do
30 end 30 end
31end 31end
32do 32do
33 local a, b
34 do
35 local _obj_0 = {
36 2,
37 3
38 }
39 a, b = _obj_0[1], _obj_0[2]
40 end
41end
42do
33 local v <close> = (function() 43 local v <close> = (function()
34 if flag then 44 if flag then
35 return func() 45 return func()
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;
80class In_t; 80class In_t;
81class NormalDef_t; 81class NormalDef_t;
82class SpreadListExp_t; 82class SpreadListExp_t;
83class Comprehension_t;
83} // namespace yue 84} // namespace yue
84 85
85AST_LEAF(Num) 86AST_LEAF(Num)
@@ -171,7 +172,7 @@ AST_END(CloseAttrib, "close"sv)
171AST_NODE(LocalAttrib) 172AST_NODE(LocalAttrib)
172 ast_sel<true, ConstAttrib_t, CloseAttrib_t> attrib; 173 ast_sel<true, ConstAttrib_t, CloseAttrib_t> attrib;
173 ast_ptr<true, Seperator_t> sep; 174 ast_ptr<true, Seperator_t> sep;
174 ast_sel_list<true, Variable_t, SimpleTable_t, TableLit_t> leftList; 175 ast_sel_list<true, Variable_t, SimpleTable_t, TableLit_t, Comprehension_t> leftList;
175 ast_ptr<true, Assign_t> assign; 176 ast_ptr<true, Assign_t> assign;
176 AST_MEMBER(LocalAttrib, &attrib, &sep, &leftList, &assign) 177 AST_MEMBER(LocalAttrib, &attrib, &sep, &leftList, &assign)
177AST_END(LocalAttrib, "local_attrib"sv) 178AST_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<std::string> Metamethods = {
75 "close"s // Lua 5.4 75 "close"s // Lua 5.4
76}; 76};
77 77
78const std::string_view version = "0.21.5"sv; 78const std::string_view version = "0.21.6"sv;
79const std::string_view extension = "yue"sv; 79const std::string_view extension = "yue"sv;
80 80
81class CompileError : public std::logic_error { 81class CompileError : public std::logic_error {
@@ -9376,7 +9376,8 @@ private:
9376 case id<SimpleTable_t>(): 9376 case id<SimpleTable_t>():
9377 value->item.set(item); 9377 value->item.set(item);
9378 break; 9378 break;
9379 case id<TableLit_t>(): { 9379 case id<TableLit_t>():
9380 case id<Comprehension_t>(): {
9380 auto simpleValue = item->new_ptr<SimpleValue_t>(); 9381 auto simpleValue = item->new_ptr<SimpleValue_t>();
9381 simpleValue->value.set(item); 9382 simpleValue->value.set(item);
9382 value->item.set(simpleValue); 9383 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() {
286 286
287 ConstAttrib = key("const"); 287 ConstAttrib = key("const");
288 CloseAttrib = key("close"); 288 CloseAttrib = key("close");
289 local_const_item = Variable | SimpleTable | TableLit; 289 local_const_item = Variable | SimpleTable | TableLit | Comprehension;
290 LocalAttrib = ( 290 LocalAttrib = (
291 ConstAttrib >> Seperator >> space >> local_const_item >> *(space >> ',' >> space >> local_const_item) | 291 ConstAttrib >> Seperator >> space >> local_const_item >> *(space >> ',' >> space >> local_const_item) |
292 CloseAttrib >> Seperator >> space >> Variable >> *(space >> ',' >> space >> Variable) 292 CloseAttrib >> Seperator >> space >> Variable >> *(space >> ',' >> space >> Variable)