From cf2e784581df4d24b03b85f0ac02514a166150b6 Mon Sep 17 00:00:00 2001 From: Li Jin Date: Fri, 22 Sep 2023 11:53:24 +0800 Subject: fixing issue #149. --- src/yuescript/yue_ast.cpp | 2 +- src/yuescript/yue_ast.h | 4 ++-- src/yuescript/yue_compiler.cpp | 11 ++++++++--- src/yuescript/yue_parser.cpp | 2 +- 4 files changed, 12 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/yuescript/yue_ast.cpp b/src/yuescript/yue_ast.cpp index 105bd74..39f19ea 100644 --- a/src/yuescript/yue_ast.cpp +++ b/src/yuescript/yue_ast.cpp @@ -269,7 +269,7 @@ std::string ImportFrom_t::to_string(void* ud) const { for (auto name : names.objects()) { temp.emplace_back(name->to_string(ud)); } - return join(temp, ", "sv) + " from "s + exp->to_string(ud); + return join(temp, ", "sv) + " from "s + item->to_string(ud); } std::string MacroNamePair_t::to_string(void* ud) const { return key->to_string(ud) + ": "s + value->to_string(ud); diff --git a/src/yuescript/yue_ast.h b/src/yuescript/yue_ast.h index a7f897c..78f6c9f 100644 --- a/src/yuescript/yue_ast.h +++ b/src/yuescript/yue_ast.h @@ -191,8 +191,8 @@ AST_END(ImportLiteral, "import_literal"sv) AST_NODE(ImportFrom) ast_ptr sep; ast_sel_list names; - ast_ptr exp; - AST_MEMBER(ImportFrom, &sep, &names, &exp) + ast_sel item; + AST_MEMBER(ImportFrom, &sep, &names, &item) AST_END(ImportFrom, "import_from"sv) AST_NODE(MacroNamePair) diff --git a/src/yuescript/yue_compiler.cpp b/src/yuescript/yue_compiler.cpp index 42b92a4..3c11429 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.2"sv; +const std::string_view version = "0.19.3"sv; const std::string_view extension = "yue"sv; class CompileError : public std::logic_error { @@ -8375,13 +8375,18 @@ private: void transformImportFrom(ImportFrom_t* import, str_list& out) { str_list temp; auto x = import; - auto objVar = singleVariableFrom(import->exp, true); + auto objVar = singleVariableFrom(import->item, true); ast_ptr objAssign; if (objVar.empty()) { objVar = getUnusedName("_obj_"sv); auto expList = toAst(objVar, x); auto assign = x->new_ptr(); - assign->values.push_back(import->exp); + if (import->item.is()) { + assign->values.push_back(import->item); + } else { + auto exp = toAst("require "s + _parser.toString(import->item.to()), import->item); + assign->values.push_back(exp); + } auto assignment = x->new_ptr(); assignment->expList.set(expList); assignment->action.set(assign); diff --git a/src/yuescript/yue_parser.cpp b/src/yuescript/yue_parser.cpp index ff7660a..6ba9b13 100644 --- a/src/yuescript/yue_parser.cpp +++ b/src/yuescript/yue_parser.cpp @@ -285,7 +285,7 @@ YueParser::YueParser() { ColonImportName = '\\' >> space >> Variable; 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 >> Exp; + ImportFrom = import_name_list >> *space_break >> space >> key("from") >> space >> (ImportLiteral | not_(String) >> Exp); ImportLiteralInner = (range('a', 'z') | range('A', 'Z') | set("_-") | larger(255)) >> *(alpha_num | '-' | larger(255)); import_literal_chain = Seperator >> ImportLiteralInner >> *('.' >> ImportLiteralInner); -- cgit v1.2.3-55-g6feb