From f61a4a1d9a1b979b8a0c2e8a9c194a284f42220f Mon Sep 17 00:00:00 2001 From: Li Jin Date: Tue, 17 Oct 2023 22:34:06 +0800 Subject: fixing issue #153. --- spec/inputs/import.yue | 36 ++++++++++++++++++++++++++++++++++++ spec/outputs/import.lua | 16 ++++++++++++++++ src/yuescript/yue_compiler.cpp | 3 ++- src/yuescript/yue_parser.cpp | 20 +++++++++++--------- src/yuescript/yue_parser.h | 2 ++ 5 files changed, 67 insertions(+), 10 deletions(-) diff --git a/spec/inputs/import.yue b/spec/inputs/import.yue index 7a21995..b8ffc24 100644 --- a/spec/inputs/import.yue +++ b/spec/inputs/import.yue @@ -75,6 +75,42 @@ do b c +do + from UnityEngine import Object + GameObject + Transform + MonoBehaviour + Vector3 + Quaternion + + speed = 10 + +do + from UnityEngine import Object, GameObject, + Transform + MonoBehaviour + Vector3 + Quaternion + + speed = 10 + +do + from UnityEngine import Object, GameObject, + Transform, + MonoBehaviour + Vector3, Quaternion + + update speed + +do + from UnityEngine import + Object, GameObject, + Transform, + MonoBehaviour + Vector3, Quaternion + + update speed + do import 'module' import 'module_x' diff --git a/spec/outputs/import.lua b/spec/outputs/import.lua index ef83f2d..270c7b7 100644 --- a/spec/outputs/import.lua +++ b/spec/outputs/import.lua @@ -112,6 +112,22 @@ end do local a, b, c = z.a, z.b, z.c end +do + local Object, GameObject, Transform, MonoBehaviour, Vector3, Quaternion = UnityEngine.Object, UnityEngine.GameObject, UnityEngine.Transform, UnityEngine.MonoBehaviour, UnityEngine.Vector3, UnityEngine.Quaternion + local speed = 10 +end +do + local Object, GameObject, Transform, MonoBehaviour, Vector3, Quaternion = UnityEngine.Object, UnityEngine.GameObject, UnityEngine.Transform, UnityEngine.MonoBehaviour, UnityEngine.Vector3, UnityEngine.Quaternion + local speed = 10 +end +do + local Object, GameObject, Transform, MonoBehaviour, Vector3, Quaternion = UnityEngine.Object, UnityEngine.GameObject, UnityEngine.Transform, UnityEngine.MonoBehaviour, UnityEngine.Vector3, UnityEngine.Quaternion + update(speed) +end +do + local Object, GameObject, Transform, MonoBehaviour, Vector3, Quaternion = UnityEngine.Object, UnityEngine.GameObject, UnityEngine.Transform, UnityEngine.MonoBehaviour, UnityEngine.Vector3, UnityEngine.Quaternion + update(speed) +end do local module = require('module') local module_x = require('module_x') diff --git a/src/yuescript/yue_compiler.cpp b/src/yuescript/yue_compiler.cpp index fa7be45..5b9770d 100644 --- a/src/yuescript/yue_compiler.cpp +++ b/src/yuescript/yue_compiler.cpp @@ -74,7 +74,7 @@ static std::unordered_set Metamethods = { "close"s // Lua 5.4 }; -const std::string_view version = "0.19.5"sv; +const std::string_view version = "0.19.6"sv; const std::string_view extension = "yue"sv; class CompileError : public std::logic_error { @@ -2632,6 +2632,7 @@ private: break; default: YUEE("AST node mismatch", destructNode); break; } + if (dlist->empty()) throw CompileError("expect items to be destructured"sv, destructNode); for (auto item : *dlist) { switch (item->get_id()) { case id(): { diff --git a/src/yuescript/yue_parser.cpp b/src/yuescript/yue_parser.cpp index 5d2b4c9..c818098 100644 --- a/src/yuescript/yue_parser.cpp +++ b/src/yuescript/yue_parser.cpp @@ -286,7 +286,9 @@ YueParser::YueParser() { import_name = ColonImportName | Variable; import_name_list = Seperator >> *space_break >> space >> import_name >> *((+space_break | space >> ',' >> *space_break) >> space >> import_name); ImportFrom = import_name_list >> *space_break >> space >> key("from") >> space >> (ImportLiteral | not_(String) >> Exp); - FromImport = key("from") >> space >> (ImportLiteral | not_(String) >> Exp) >> *space_break >> space >> key("import") >> space >> import_name_list; + from_import_name_list_line = import_name >> *(space >> ',' >> space >> import_name); + from_import_name_in_block = +space_break >> advance_match >> ensure(space >> from_import_name_list_line >> *(-(space >> ',') >> +space_break >> check_indent_match >> space >> from_import_name_list_line), pop_indent); + FromImport = key("from") >> space >> (ImportLiteral | not_(String) >> Exp) >> *space_break >> space >> key("import") >> space >> Seperator >> (from_import_name_list_line >> -(space >> ',') >> -from_import_name_in_block | from_import_name_in_block); ImportLiteralInner = (range('a', 'z') | range('A', 'Z') | set("_-") | larger(255)) >> *(alpha_num | '-' | larger(255)); import_literal_chain = Seperator >> ImportLiteralInner >> *('.' >> ImportLiteralInner); @@ -653,6 +655,14 @@ YueParser::YueParser() { SpreadExp | NormalDef; + table_value_list = table_value >> *(space >> ',' >> space >> table_value); + + table_lit_line = ( + push_indent_match >> (space >> table_value_list >> pop_indent | pop_indent) + ) | ( + space + ); + table_lit_lines = space_break >> table_lit_line >> *(-(space >> ',') >> space_break >> table_lit_line) >> -(space >> ','); TableLit = @@ -662,14 +672,6 @@ YueParser::YueParser() { -table_lit_lines >> white >> '}'; - table_value_list = table_value >> *(space >> ',' >> space >> table_value); - - table_lit_line = ( - push_indent_match >> (space >> table_value_list >> pop_indent | pop_indent) - ) | ( - space - ); - table_block_inner = Seperator >> key_value_line >> *(+space_break >> key_value_line); TableBlock = +space_break >> advance_match >> ensure(table_block_inner, pop_indent); TableBlockIndent = '*' >> Seperator >> disable_arg_table_block_rule( diff --git a/src/yuescript/yue_parser.h b/src/yuescript/yue_parser.h index 874bbc8..7864300 100644 --- a/src/yuescript/yue_parser.h +++ b/src/yuescript/yue_parser.h @@ -177,6 +177,8 @@ private: NONE_AST_RULE(in_block); NONE_AST_RULE(import_name); NONE_AST_RULE(import_name_list); + NONE_AST_RULE(from_import_name_list_line); + NONE_AST_RULE(from_import_name_in_block); NONE_AST_RULE(import_literal_chain); NONE_AST_RULE(import_tab_item); NONE_AST_RULE(import_tab_list); -- cgit v1.2.3-55-g6feb