diff options
-rw-r--r-- | spec/inputs/destructure.yue | 8 | ||||
-rw-r--r-- | spec/outputs/destructure.lua | 24 | ||||
-rw-r--r-- | src/yuescript/LICENSE.md | 21 | ||||
-rw-r--r-- | src/yuescript/yue_ast.h | 2 | ||||
-rw-r--r-- | src/yuescript/yue_compiler.cpp | 9 | ||||
-rw-r--r-- | src/yuescript/yue_parser.cpp | 2 |
6 files changed, 63 insertions, 3 deletions
diff --git a/spec/inputs/destructure.yue b/spec/inputs/destructure.yue index d161fd8..73e4d33 100644 --- a/spec/inputs/destructure.yue +++ b/spec/inputs/destructure.yue | |||
@@ -80,6 +80,8 @@ do | |||
80 | for {x,y} in *thing | 80 | for {x,y} in *thing |
81 | print x,y | 81 | print x,y |
82 | 82 | ||
83 | for [x,y] in *thing | ||
84 | print x,y | ||
83 | 85 | ||
84 | -- | 86 | -- |
85 | 87 | ||
@@ -178,10 +180,16 @@ do | |||
178 | for {left = "null", right = false} in *tuples | 180 | for {left = "null", right = false} in *tuples |
179 | print left, right | 181 | print left, right |
180 | 182 | ||
183 | for [left = "null", right = false] in *tuples | ||
184 | print left, right | ||
185 | |||
181 | do | 186 | do |
182 | {_, a, _, b} = tb -- list placeholder | 187 | {_, a, _, b} = tb -- list placeholder |
183 | 188 | ||
184 | do | 189 | do |
190 | [a, _, b, _] = tb -- list placeholder | ||
191 | |||
192 | do | ||
185 | {x: a.b = 1, y: a.c = 2} = x.x.x | 193 | {x: a.b = 1, y: a.c = 2} = x.x.x |
186 | 194 | ||
187 | do | 195 | do |
diff --git a/spec/outputs/destructure.lua b/spec/outputs/destructure.lua index 25e0529..38f21ff 100644 --- a/spec/outputs/destructure.lua +++ b/spec/outputs/destructure.lua | |||
@@ -124,6 +124,11 @@ do | |||
124 | local x, y = _des_0[1], _des_0[2] | 124 | local x, y = _des_0[1], _des_0[2] |
125 | print(x, y) | 125 | print(x, y) |
126 | end | 126 | end |
127 | for _index_0 = 1, #thing do | ||
128 | local _des_0 = thing[_index_0] | ||
129 | local x, y = _des_0[1], _des_0[2] | ||
130 | print(x, y) | ||
131 | end | ||
127 | end | 132 | end |
128 | do | 133 | do |
129 | do | 134 | do |
@@ -370,6 +375,18 @@ do | |||
370 | end | 375 | end |
371 | print(left, right) | 376 | print(left, right) |
372 | end | 377 | end |
378 | local _list_1 = tuples | ||
379 | for _index_0 = 1, #_list_1 do | ||
380 | local _des_0 = _list_1[_index_0] | ||
381 | local left, right = _des_0[1], _des_0[2] | ||
382 | if left == nil then | ||
383 | left = "null" | ||
384 | end | ||
385 | if right == nil then | ||
386 | right = false | ||
387 | end | ||
388 | print(left, right) | ||
389 | end | ||
373 | end | 390 | end |
374 | do | 391 | do |
375 | local a, b | 392 | local a, b |
@@ -379,6 +396,13 @@ do | |||
379 | end | 396 | end |
380 | end | 397 | end |
381 | do | 398 | do |
399 | local a, b | ||
400 | do | ||
401 | local _obj_0 = tb | ||
402 | a, b = _obj_0[1], _obj_0[3] | ||
403 | end | ||
404 | end | ||
405 | do | ||
382 | do | 406 | do |
383 | local _obj_0 = x.x.x | 407 | local _obj_0 = x.x.x |
384 | local _tmp_0, _tmp_1 = _obj_0.x, _obj_0.y | 408 | local _tmp_0, _tmp_1 = _obj_0.x, _obj_0.y |
diff --git a/src/yuescript/LICENSE.md b/src/yuescript/LICENSE.md new file mode 100644 index 0000000..b1a5fee --- /dev/null +++ b/src/yuescript/LICENSE.md | |||
@@ -0,0 +1,21 @@ | |||
1 | MIT License | ||
2 | |||
3 | Copyright (c) 2023 Li Jin | ||
4 | |||
5 | Permission is hereby granted, free of charge, to any person obtaining a copy | ||
6 | of this software and associated documentation files (the "Software"), to deal | ||
7 | in the Software without restriction, including without limitation the rights | ||
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
9 | copies of the Software, and to permit persons to whom the Software is | ||
10 | furnished to do so, subject to the following conditions: | ||
11 | |||
12 | The above copyright notice and this permission notice shall be included in all | ||
13 | copies or substantial portions of the Software. | ||
14 | |||
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
21 | SOFTWARE. | ||
diff --git a/src/yuescript/yue_ast.h b/src/yuescript/yue_ast.h index 2136849..fa47559 100644 --- a/src/yuescript/yue_ast.h +++ b/src/yuescript/yue_ast.h | |||
@@ -787,7 +787,7 @@ AST_NODE(Macro) | |||
787 | AST_END(Macro, "macro"sv) | 787 | AST_END(Macro, "macro"sv) |
788 | 788 | ||
789 | AST_NODE(NameOrDestructure) | 789 | AST_NODE(NameOrDestructure) |
790 | ast_sel<true, Variable_t, TableLit_t> item; | 790 | ast_sel<true, Variable_t, TableLit_t, Comprehension_t> item; |
791 | AST_MEMBER(NameOrDestructure, &item) | 791 | AST_MEMBER(NameOrDestructure, &item) |
792 | AST_END(NameOrDestructure, "name_or_des"sv) | 792 | AST_END(NameOrDestructure, "name_or_des"sv) |
793 | 793 | ||
diff --git a/src/yuescript/yue_compiler.cpp b/src/yuescript/yue_compiler.cpp index 0265e07..648dab2 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 | ||
78 | const std::string_view version = "0.20.2"sv; | 78 | const std::string_view version = "0.20.3"sv; |
79 | const std::string_view extension = "yue"sv; | 79 | const std::string_view extension = "yue"sv; |
80 | 80 | ||
81 | class CompileError : public std::logic_error { | 81 | class CompileError : public std::logic_error { |
@@ -6842,6 +6842,13 @@ private: | |||
6842 | varAfter.push_back(desVar); | 6842 | varAfter.push_back(desVar); |
6843 | break; | 6843 | break; |
6844 | } | 6844 | } |
6845 | case id<Comprehension_t>(): { | ||
6846 | auto desVar = getUnusedName("_des_"sv); | ||
6847 | destructPairs.emplace_back(item, toAst<Exp_t>(desVar, x)); | ||
6848 | vars.push_back(desVar); | ||
6849 | varAfter.push_back(desVar); | ||
6850 | break; | ||
6851 | } | ||
6845 | default: YUEE("AST node mismatch", item); break; | 6852 | default: YUEE("AST node mismatch", item); break; |
6846 | } | 6853 | } |
6847 | } | 6854 | } |
diff --git a/src/yuescript/yue_parser.cpp b/src/yuescript/yue_parser.cpp index 8ceee9a..11c7627 100644 --- a/src/yuescript/yue_parser.cpp +++ b/src/yuescript/yue_parser.cpp | |||
@@ -835,7 +835,7 @@ YueParser::YueParser() { | |||
835 | MacroInPlace = '$' >> space >> "->" >> space >> Body; | 835 | MacroInPlace = '$' >> space >> "->" >> space >> Body; |
836 | 836 | ||
837 | NameList = Seperator >> Variable >> *(space >> ',' >> space >> Variable); | 837 | NameList = Seperator >> Variable >> *(space >> ',' >> space >> Variable); |
838 | NameOrDestructure = Variable | TableLit; | 838 | NameOrDestructure = Variable | TableLit | Comprehension; |
839 | AssignableNameList = Seperator >> NameOrDestructure >> *(space >> ',' >> space >> NameOrDestructure); | 839 | AssignableNameList = Seperator >> NameOrDestructure >> *(space >> ',' >> space >> NameOrDestructure); |
840 | 840 | ||
841 | FnArrowBack = '<' >> set("-="); | 841 | FnArrowBack = '<' >> set("-="); |