From 7bfa002f3d4dcb62e6a301141be6d17889a94f55 Mon Sep 17 00:00:00 2001 From: Li Jin Date: Fri, 27 Oct 2023 16:58:43 +0800 Subject: fix a missing case for list destructuring. --- src/yuescript/LICENSE.md | 21 +++++++++++++++++++++ src/yuescript/yue_ast.h | 2 +- src/yuescript/yue_compiler.cpp | 9 ++++++++- src/yuescript/yue_parser.cpp | 2 +- 4 files changed, 31 insertions(+), 3 deletions(-) create mode 100644 src/yuescript/LICENSE.md (limited to 'src') 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 @@ +MIT License + +Copyright (c) 2023 Li Jin + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +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) AST_END(Macro, "macro"sv) AST_NODE(NameOrDestructure) - ast_sel item; + ast_sel item; AST_MEMBER(NameOrDestructure, &item) AST_END(NameOrDestructure, "name_or_des"sv) 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 Metamethods = { "close"s // Lua 5.4 }; -const std::string_view version = "0.20.2"sv; +const std::string_view version = "0.20.3"sv; const std::string_view extension = "yue"sv; class CompileError : public std::logic_error { @@ -6842,6 +6842,13 @@ private: varAfter.push_back(desVar); break; } + case id(): { + auto desVar = getUnusedName("_des_"sv); + destructPairs.emplace_back(item, toAst(desVar, x)); + vars.push_back(desVar); + varAfter.push_back(desVar); + break; + } default: YUEE("AST node mismatch", item); break; } } 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() { MacroInPlace = '$' >> space >> "->" >> space >> Body; NameList = Seperator >> Variable >> *(space >> ',' >> space >> Variable); - NameOrDestructure = Variable | TableLit; + NameOrDestructure = Variable | TableLit | Comprehension; AssignableNameList = Seperator >> NameOrDestructure >> *(space >> ',' >> space >> NameOrDestructure); FnArrowBack = '<' >> set("-="); -- cgit v1.2.3-55-g6feb