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. --- src/yuescript/yue_ast.h | 2 +- src/yuescript/yue_compiler.cpp | 4 +++- src/yuescript/yue_parser.cpp | 8 ++++---- 3 files changed, 8 insertions(+), 6 deletions(-) (limited to 'src') 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