diff options
author | Li Jin <dragon-fly@qq.com> | 2023-10-17 22:34:06 +0800 |
---|---|---|
committer | Li Jin <dragon-fly@qq.com> | 2023-10-17 22:34:06 +0800 |
commit | f61a4a1d9a1b979b8a0c2e8a9c194a284f42220f (patch) | |
tree | f27fbf52d5f146875d00f635f5f4f03db48816d0 | |
parent | 6d88ca63050623db73e3cfe614e9a90657f5e875 (diff) | |
download | yuescript-0.19.6.tar.gz yuescript-0.19.6.tar.bz2 yuescript-0.19.6.zip |
fixing issue #153.v0.19.6
-rw-r--r-- | spec/inputs/import.yue | 36 | ||||
-rw-r--r-- | spec/outputs/import.lua | 16 | ||||
-rw-r--r-- | src/yuescript/yue_compiler.cpp | 3 | ||||
-rw-r--r-- | src/yuescript/yue_parser.cpp | 20 | ||||
-rw-r--r-- | 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 | |||
@@ -76,6 +76,42 @@ do | |||
76 | c | 76 | c |
77 | 77 | ||
78 | do | 78 | do |
79 | from UnityEngine import Object | ||
80 | GameObject | ||
81 | Transform | ||
82 | MonoBehaviour | ||
83 | Vector3 | ||
84 | Quaternion | ||
85 | |||
86 | speed = 10 | ||
87 | |||
88 | do | ||
89 | from UnityEngine import Object, GameObject, | ||
90 | Transform | ||
91 | MonoBehaviour | ||
92 | Vector3 | ||
93 | Quaternion | ||
94 | |||
95 | speed = 10 | ||
96 | |||
97 | do | ||
98 | from UnityEngine import Object, GameObject, | ||
99 | Transform, | ||
100 | MonoBehaviour | ||
101 | Vector3, Quaternion | ||
102 | |||
103 | update speed | ||
104 | |||
105 | do | ||
106 | from UnityEngine import | ||
107 | Object, GameObject, | ||
108 | Transform, | ||
109 | MonoBehaviour | ||
110 | Vector3, Quaternion | ||
111 | |||
112 | update speed | ||
113 | |||
114 | do | ||
79 | import 'module' | 115 | import 'module' |
80 | import 'module_x' | 116 | import 'module_x' |
81 | import "d-a-s-h-e-s" | 117 | import "d-a-s-h-e-s" |
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 | |||
@@ -113,6 +113,22 @@ do | |||
113 | local a, b, c = z.a, z.b, z.c | 113 | local a, b, c = z.a, z.b, z.c |
114 | end | 114 | end |
115 | do | 115 | do |
116 | local Object, GameObject, Transform, MonoBehaviour, Vector3, Quaternion = UnityEngine.Object, UnityEngine.GameObject, UnityEngine.Transform, UnityEngine.MonoBehaviour, UnityEngine.Vector3, UnityEngine.Quaternion | ||
117 | local speed = 10 | ||
118 | end | ||
119 | do | ||
120 | local Object, GameObject, Transform, MonoBehaviour, Vector3, Quaternion = UnityEngine.Object, UnityEngine.GameObject, UnityEngine.Transform, UnityEngine.MonoBehaviour, UnityEngine.Vector3, UnityEngine.Quaternion | ||
121 | local speed = 10 | ||
122 | end | ||
123 | do | ||
124 | local Object, GameObject, Transform, MonoBehaviour, Vector3, Quaternion = UnityEngine.Object, UnityEngine.GameObject, UnityEngine.Transform, UnityEngine.MonoBehaviour, UnityEngine.Vector3, UnityEngine.Quaternion | ||
125 | update(speed) | ||
126 | end | ||
127 | do | ||
128 | local Object, GameObject, Transform, MonoBehaviour, Vector3, Quaternion = UnityEngine.Object, UnityEngine.GameObject, UnityEngine.Transform, UnityEngine.MonoBehaviour, UnityEngine.Vector3, UnityEngine.Quaternion | ||
129 | update(speed) | ||
130 | end | ||
131 | do | ||
116 | local module = require('module') | 132 | local module = require('module') |
117 | local module_x = require('module_x') | 133 | local module_x = require('module_x') |
118 | local d_a_s_h_e_s = require("d-a-s-h-e-s") | 134 | local d_a_s_h_e_s = require("d-a-s-h-e-s") |
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<std::string> Metamethods = { | |||
74 | "close"s // Lua 5.4 | 74 | "close"s // Lua 5.4 |
75 | }; | 75 | }; |
76 | 76 | ||
77 | const std::string_view version = "0.19.5"sv; | 77 | const std::string_view version = "0.19.6"sv; |
78 | const std::string_view extension = "yue"sv; | 78 | const std::string_view extension = "yue"sv; |
79 | 79 | ||
80 | class CompileError : public std::logic_error { | 80 | class CompileError : public std::logic_error { |
@@ -2632,6 +2632,7 @@ private: | |||
2632 | break; | 2632 | break; |
2633 | default: YUEE("AST node mismatch", destructNode); break; | 2633 | default: YUEE("AST node mismatch", destructNode); break; |
2634 | } | 2634 | } |
2635 | if (dlist->empty()) throw CompileError("expect items to be destructured"sv, destructNode); | ||
2635 | for (auto item : *dlist) { | 2636 | for (auto item : *dlist) { |
2636 | switch (item->get_id()) { | 2637 | switch (item->get_id()) { |
2637 | case id<MetaVariablePairDef_t>(): { | 2638 | case id<MetaVariablePairDef_t>(): { |
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() { | |||
286 | import_name = ColonImportName | Variable; | 286 | import_name = ColonImportName | Variable; |
287 | import_name_list = Seperator >> *space_break >> space >> import_name >> *((+space_break | space >> ',' >> *space_break) >> space >> import_name); | 287 | import_name_list = Seperator >> *space_break >> space >> import_name >> *((+space_break | space >> ',' >> *space_break) >> space >> import_name); |
288 | ImportFrom = import_name_list >> *space_break >> space >> key("from") >> space >> (ImportLiteral | not_(String) >> Exp); | 288 | ImportFrom = import_name_list >> *space_break >> space >> key("from") >> space >> (ImportLiteral | not_(String) >> Exp); |
289 | FromImport = key("from") >> space >> (ImportLiteral | not_(String) >> Exp) >> *space_break >> space >> key("import") >> space >> import_name_list; | 289 | from_import_name_list_line = import_name >> *(space >> ',' >> space >> import_name); |
290 | 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); | ||
291 | 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); | ||
290 | 292 | ||
291 | ImportLiteralInner = (range('a', 'z') | range('A', 'Z') | set("_-") | larger(255)) >> *(alpha_num | '-' | larger(255)); | 293 | ImportLiteralInner = (range('a', 'z') | range('A', 'Z') | set("_-") | larger(255)) >> *(alpha_num | '-' | larger(255)); |
292 | import_literal_chain = Seperator >> ImportLiteralInner >> *('.' >> ImportLiteralInner); | 294 | import_literal_chain = Seperator >> ImportLiteralInner >> *('.' >> ImportLiteralInner); |
@@ -653,6 +655,14 @@ YueParser::YueParser() { | |||
653 | SpreadExp | | 655 | SpreadExp | |
654 | NormalDef; | 656 | NormalDef; |
655 | 657 | ||
658 | table_value_list = table_value >> *(space >> ',' >> space >> table_value); | ||
659 | |||
660 | table_lit_line = ( | ||
661 | push_indent_match >> (space >> table_value_list >> pop_indent | pop_indent) | ||
662 | ) | ( | ||
663 | space | ||
664 | ); | ||
665 | |||
656 | table_lit_lines = space_break >> table_lit_line >> *(-(space >> ',') >> space_break >> table_lit_line) >> -(space >> ','); | 666 | table_lit_lines = space_break >> table_lit_line >> *(-(space >> ',') >> space_break >> table_lit_line) >> -(space >> ','); |
657 | 667 | ||
658 | TableLit = | 668 | TableLit = |
@@ -662,14 +672,6 @@ YueParser::YueParser() { | |||
662 | -table_lit_lines >> | 672 | -table_lit_lines >> |
663 | white >> '}'; | 673 | white >> '}'; |
664 | 674 | ||
665 | table_value_list = table_value >> *(space >> ',' >> space >> table_value); | ||
666 | |||
667 | table_lit_line = ( | ||
668 | push_indent_match >> (space >> table_value_list >> pop_indent | pop_indent) | ||
669 | ) | ( | ||
670 | space | ||
671 | ); | ||
672 | |||
673 | table_block_inner = Seperator >> key_value_line >> *(+space_break >> key_value_line); | 675 | table_block_inner = Seperator >> key_value_line >> *(+space_break >> key_value_line); |
674 | TableBlock = +space_break >> advance_match >> ensure(table_block_inner, pop_indent); | 676 | TableBlock = +space_break >> advance_match >> ensure(table_block_inner, pop_indent); |
675 | TableBlockIndent = '*' >> Seperator >> disable_arg_table_block_rule( | 677 | 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: | |||
177 | NONE_AST_RULE(in_block); | 177 | NONE_AST_RULE(in_block); |
178 | NONE_AST_RULE(import_name); | 178 | NONE_AST_RULE(import_name); |
179 | NONE_AST_RULE(import_name_list); | 179 | NONE_AST_RULE(import_name_list); |
180 | NONE_AST_RULE(from_import_name_list_line); | ||
181 | NONE_AST_RULE(from_import_name_in_block); | ||
180 | NONE_AST_RULE(import_literal_chain); | 182 | NONE_AST_RULE(import_literal_chain); |
181 | NONE_AST_RULE(import_tab_item); | 183 | NONE_AST_RULE(import_tab_item); |
182 | NONE_AST_RULE(import_tab_list); | 184 | NONE_AST_RULE(import_tab_list); |