aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLi Jin <dragon-fly@qq.com>2021-02-22 17:47:17 +0800
committerLi Jin <dragon-fly@qq.com>2021-02-22 17:47:17 +0800
commitaaabed2ef2d0e5b97ce1e25d7590cc41de6480f3 (patch)
treeef9ab1a4f1bf25b37f592a3c841483168502ec83
parentc44cab60b7b6cf0a36e1dd011c2fe483e8d87b38 (diff)
downloadyuescript-aaabed2ef2d0e5b97ce1e25d7590cc41de6480f3.tar.gz
yuescript-aaabed2ef2d0e5b97ce1e25d7590cc41de6480f3.tar.bz2
yuescript-aaabed2ef2d0e5b97ce1e25d7590cc41de6480f3.zip
simplify and extend import syntax.
-rw-r--r--spec/inputs/import.yue5
-rw-r--r--spec/inputs/syntax.yue4
-rw-r--r--src/yuescript/yue_ast.h2
-rw-r--r--src/yuescript/yue_compiler.cpp4
-rw-r--r--src/yuescript/yue_parser.cpp8
5 files changed, 15 insertions, 8 deletions
diff --git a/spec/inputs/import.yue b/spec/inputs/import.yue
index e075404..6330bcb 100644
--- a/spec/inputs/import.yue
+++ b/spec/inputs/import.yue
@@ -56,7 +56,8 @@ do
56do 56do
57 import "player" as Player 57 import "player" as Player
58 import "lpeg" as {:C, :Ct, :Cmt} 58 import "lpeg" as {:C, :Ct, :Cmt}
59 import "export" as {Something:{umm:{ch}}} 59 import "export" as {one, two, Something:{umm:{ch}}}
60 import "export" as :Another
60 61
61do 62do
62 global * 63 global *
@@ -65,4 +66,4 @@ do
65 import "org.package.module-y" 66 import "org.package.module-y"
66 67
67do 68do
68 import "org.package.module" as {function:func, if:ifVar} 69 import "org.package.module" as function:func, if:ifVar
diff --git a/spec/inputs/syntax.yue b/spec/inputs/syntax.yue
index 4df5785..aed4144 100644
--- a/spec/inputs/syntax.yue
+++ b/spec/inputs/syntax.yue
@@ -194,6 +194,10 @@ hello =
194 function: "okay" 194 function: "okay"
195 good: 230203 195 good: 230203
196 196
197tb = {
198 do: b
199 do :b
200}
197 201
198div class: "cool" 202div class: "cool"
199 203
diff --git a/src/yuescript/yue_ast.h b/src/yuescript/yue_ast.h
index 090765c..2d4814d 100644
--- a/src/yuescript/yue_ast.h
+++ b/src/yuescript/yue_ast.h
@@ -164,7 +164,7 @@ class normal_pair_t;
164 164
165AST_NODE(ImportTabLit) 165AST_NODE(ImportTabLit)
166 ast_ptr<true, Seperator_t> sep; 166 ast_ptr<true, Seperator_t> sep;
167 ast_sel_list<false, variable_pair_t, normal_pair_t, MacroName_t, macro_name_pair_t, import_all_macro_t> items; 167 ast_sel_list<false, variable_pair_t, normal_pair_t, MacroName_t, macro_name_pair_t, import_all_macro_t, Exp_t> items;
168 AST_MEMBER(ImportTabLit, &sep, &items) 168 AST_MEMBER(ImportTabLit, &sep, &items)
169AST_END(ImportTabLit) 169AST_END(ImportTabLit)
170 170
diff --git a/src/yuescript/yue_compiler.cpp b/src/yuescript/yue_compiler.cpp
index ebc2b3f..b07a998 100644
--- a/src/yuescript/yue_compiler.cpp
+++ b/src/yuescript/yue_compiler.cpp
@@ -58,7 +58,7 @@ inline std::string s(std::string_view sv) {
58 return std::string(sv); 58 return std::string(sv);
59} 59}
60 60
61const std::string_view version = "0.6.8"sv; 61const std::string_view version = "0.6.9"sv;
62const std::string_view extension = "yue"sv; 62const std::string_view extension = "yue"sv;
63 63
64class YueCompilerImpl { 64class YueCompilerImpl {
@@ -5236,6 +5236,7 @@ private:
5236 break; 5236 break;
5237 case id<variable_pair_t>(): 5237 case id<variable_pair_t>():
5238 case id<normal_pair_t>(): 5238 case id<normal_pair_t>():
5239 case id<Exp_t>():
5239 newTab->items.push_back(item); 5240 newTab->items.push_back(item);
5240 break; 5241 break;
5241 default: YUEE("AST node mismatch", item); break; 5242 default: YUEE("AST node mismatch", item); break;
@@ -5308,6 +5309,7 @@ private:
5308 } 5309 }
5309 case id<variable_pair_t>(): 5310 case id<variable_pair_t>():
5310 case id<normal_pair_t>(): 5311 case id<normal_pair_t>():
5312 case id<Exp_t>():
5311 newTab->items.push_back(item); 5313 newTab->items.push_back(item);
5312 break; 5314 break;
5313 default: YUEE("AST node mismatch", item); break; 5315 default: YUEE("AST node mismatch", item); break;
diff --git a/src/yuescript/yue_parser.cpp b/src/yuescript/yue_parser.cpp
index cf3da01..7cf2ebe 100644
--- a/src/yuescript/yue_parser.cpp
+++ b/src/yuescript/yue_parser.cpp
@@ -199,20 +199,20 @@ YueParser::YueParser() {
199 199
200 macro_name_pair = Space >> MacroName >> Space >> symx(':') >> Space >> MacroName; 200 macro_name_pair = Space >> MacroName >> Space >> symx(':') >> Space >> MacroName;
201 import_all_macro = expr('$'); 201 import_all_macro = expr('$');
202 ImportTabItem = variable_pair | normal_pair | sym(':') >> MacroName | macro_name_pair | Space >> import_all_macro; 202 ImportTabItem = variable_pair | normal_pair | sym(':') >> MacroName | macro_name_pair | Space >> import_all_macro | Exp;
203 ImportTabList = ImportTabItem >> *(sym(',') >> ImportTabItem); 203 ImportTabList = ImportTabItem >> *(sym(',') >> ImportTabItem);
204 ImportTabLine = ( 204 ImportTabLine = (
205 PushIndent >> (ImportTabList >> PopIndent | PopIndent) 205 PushIndent >> (ImportTabList >> PopIndent | PopIndent)
206 ) | Space; 206 ) | Space;
207 import_tab_lines = SpaceBreak >> ImportTabLine >> *(-sym(',') >> SpaceBreak >> ImportTabLine) >> -sym(','); 207 import_tab_lines = SpaceBreak >> ImportTabLine >> *(-sym(',') >> SpaceBreak >> ImportTabLine) >> -sym(',');
208 ImportTabLit = 208 ImportTabLit =
209 sym('{') >> Seperator >> 209 Seperator >> (sym('{') >>
210 -ImportTabList >> 210 -ImportTabList >>
211 -sym(',') >> 211 -sym(',') >>
212 -import_tab_lines >> 212 -import_tab_lines >>
213 White >> sym('}'); 213 White >> sym('}') | KeyValue >> *(sym(',') >> KeyValue));
214 214
215 ImportAs = ImportLiteral >> -(key("as") >> (Space >> Variable | ImportTabLit)); 215 ImportAs = ImportLiteral >> -(key("as") >> (ImportTabLit | Space >> Variable));
216 216
217 Import = key("import") >> (ImportAs | ImportFrom); 217 Import = key("import") >> (ImportAs | ImportFrom);
218 218