diff options
| author | Li Jin <dragon-fly@qq.com> | 2023-10-27 16:58:43 +0800 |
|---|---|---|
| committer | Li Jin <dragon-fly@qq.com> | 2023-10-27 16:58:43 +0800 |
| commit | 7bfa002f3d4dcb62e6a301141be6d17889a94f55 (patch) | |
| tree | 927eab759af3e333b1f7d80c3724ec4b869c02e1 /src | |
| parent | bafe9b44212316a51ee00f7af15e881c81d96fe6 (diff) | |
| download | yuescript-7bfa002f3d4dcb62e6a301141be6d17889a94f55.tar.gz yuescript-7bfa002f3d4dcb62e6a301141be6d17889a94f55.tar.bz2 yuescript-7bfa002f3d4dcb62e6a301141be6d17889a94f55.zip | |
fix a missing case for list destructuring.
Diffstat (limited to '')
| -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 |
4 files changed, 31 insertions, 3 deletions
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("-="); |
