From aaabed2ef2d0e5b97ce1e25d7590cc41de6480f3 Mon Sep 17 00:00:00 2001 From: Li Jin Date: Mon, 22 Feb 2021 17:47:17 +0800 Subject: simplify and extend import syntax. --- spec/inputs/import.yue | 5 +++-- spec/inputs/syntax.yue | 4 ++++ src/yuescript/yue_ast.h | 2 +- src/yuescript/yue_compiler.cpp | 4 +++- src/yuescript/yue_parser.cpp | 8 ++++---- 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 do import "player" as Player import "lpeg" as {:C, :Ct, :Cmt} - import "export" as {Something:{umm:{ch}}} + import "export" as {one, two, Something:{umm:{ch}}} + import "export" as :Another do global * @@ -65,4 +66,4 @@ do import "org.package.module-y" do - import "org.package.module" as {function:func, if:ifVar} + 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 = function: "okay" good: 230203 +tb = { + do: b + do :b +} div class: "cool" 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; AST_NODE(ImportTabLit) ast_ptr sep; - ast_sel_list items; + ast_sel_list items; AST_MEMBER(ImportTabLit, &sep, &items) AST_END(ImportTabLit) 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) { return std::string(sv); } -const std::string_view version = "0.6.8"sv; +const std::string_view version = "0.6.9"sv; const std::string_view extension = "yue"sv; class YueCompilerImpl { @@ -5236,6 +5236,7 @@ private: break; case id(): case id(): + case id(): newTab->items.push_back(item); break; default: YUEE("AST node mismatch", item); break; @@ -5308,6 +5309,7 @@ private: } case id(): case id(): + case id(): newTab->items.push_back(item); break; 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() { macro_name_pair = Space >> MacroName >> Space >> symx(':') >> Space >> MacroName; import_all_macro = expr('$'); - ImportTabItem = variable_pair | normal_pair | sym(':') >> MacroName | macro_name_pair | Space >> import_all_macro; + ImportTabItem = variable_pair | normal_pair | sym(':') >> MacroName | macro_name_pair | Space >> import_all_macro | Exp; ImportTabList = ImportTabItem >> *(sym(',') >> ImportTabItem); ImportTabLine = ( PushIndent >> (ImportTabList >> PopIndent | PopIndent) ) | Space; import_tab_lines = SpaceBreak >> ImportTabLine >> *(-sym(',') >> SpaceBreak >> ImportTabLine) >> -sym(','); ImportTabLit = - sym('{') >> Seperator >> + Seperator >> (sym('{') >> -ImportTabList >> -sym(',') >> -import_tab_lines >> - White >> sym('}'); + White >> sym('}') | KeyValue >> *(sym(',') >> KeyValue)); - ImportAs = ImportLiteral >> -(key("as") >> (Space >> Variable | ImportTabLit)); + ImportAs = ImportLiteral >> -(key("as") >> (ImportTabLit | Space >> Variable)); Import = key("import") >> (ImportAs | ImportFrom); -- cgit v1.2.3-55-g6feb