diff options
author | Li Jin <dragon-fly@qq.com> | 2023-09-22 11:53:24 +0800 |
---|---|---|
committer | Li Jin <dragon-fly@qq.com> | 2023-09-22 11:53:24 +0800 |
commit | cf2e784581df4d24b03b85f0ac02514a166150b6 (patch) | |
tree | 2c7bcd1e5c27ae7018b30843b175ecfadbd6af96 /src | |
parent | 42f973f85ba7e3934111aa53588b43049c123a56 (diff) | |
download | yuescript-cf2e784581df4d24b03b85f0ac02514a166150b6.tar.gz yuescript-cf2e784581df4d24b03b85f0ac02514a166150b6.tar.bz2 yuescript-cf2e784581df4d24b03b85f0ac02514a166150b6.zip |
fixing issue #149.
Diffstat (limited to 'src')
-rw-r--r-- | src/yuescript/yue_ast.cpp | 2 | ||||
-rw-r--r-- | src/yuescript/yue_ast.h | 4 | ||||
-rw-r--r-- | src/yuescript/yue_compiler.cpp | 11 | ||||
-rw-r--r-- | src/yuescript/yue_parser.cpp | 2 |
4 files changed, 12 insertions, 7 deletions
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 { | |||
269 | for (auto name : names.objects()) { | 269 | for (auto name : names.objects()) { |
270 | temp.emplace_back(name->to_string(ud)); | 270 | temp.emplace_back(name->to_string(ud)); |
271 | } | 271 | } |
272 | return join(temp, ", "sv) + " from "s + exp->to_string(ud); | 272 | return join(temp, ", "sv) + " from "s + item->to_string(ud); |
273 | } | 273 | } |
274 | std::string MacroNamePair_t::to_string(void* ud) const { | 274 | std::string MacroNamePair_t::to_string(void* ud) const { |
275 | return key->to_string(ud) + ": "s + value->to_string(ud); | 275 | 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) | |||
191 | AST_NODE(ImportFrom) | 191 | AST_NODE(ImportFrom) |
192 | ast_ptr<true, Seperator_t> sep; | 192 | ast_ptr<true, Seperator_t> sep; |
193 | ast_sel_list<true, ColonImportName_t, Variable_t> names; | 193 | ast_sel_list<true, ColonImportName_t, Variable_t> names; |
194 | ast_ptr<true, Exp_t> exp; | 194 | ast_sel<true, ImportLiteral_t, Exp_t> item; |
195 | AST_MEMBER(ImportFrom, &sep, &names, &exp) | 195 | AST_MEMBER(ImportFrom, &sep, &names, &item) |
196 | AST_END(ImportFrom, "import_from"sv) | 196 | AST_END(ImportFrom, "import_from"sv) |
197 | 197 | ||
198 | AST_NODE(MacroNamePair) | 198 | 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<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.2"sv; | 77 | const std::string_view version = "0.19.3"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 { |
@@ -8375,13 +8375,18 @@ private: | |||
8375 | void transformImportFrom(ImportFrom_t* import, str_list& out) { | 8375 | void transformImportFrom(ImportFrom_t* import, str_list& out) { |
8376 | str_list temp; | 8376 | str_list temp; |
8377 | auto x = import; | 8377 | auto x = import; |
8378 | auto objVar = singleVariableFrom(import->exp, true); | 8378 | auto objVar = singleVariableFrom(import->item, true); |
8379 | ast_ptr<false, ExpListAssign_t> objAssign; | 8379 | ast_ptr<false, ExpListAssign_t> objAssign; |
8380 | if (objVar.empty()) { | 8380 | if (objVar.empty()) { |
8381 | objVar = getUnusedName("_obj_"sv); | 8381 | objVar = getUnusedName("_obj_"sv); |
8382 | auto expList = toAst<ExpList_t>(objVar, x); | 8382 | auto expList = toAst<ExpList_t>(objVar, x); |
8383 | auto assign = x->new_ptr<Assign_t>(); | 8383 | auto assign = x->new_ptr<Assign_t>(); |
8384 | assign->values.push_back(import->exp); | 8384 | if (import->item.is<Exp_t>()) { |
8385 | assign->values.push_back(import->item); | ||
8386 | } else { | ||
8387 | auto exp = toAst<Exp_t>("require "s + _parser.toString(import->item.to<ImportLiteral_t>()), import->item); | ||
8388 | assign->values.push_back(exp); | ||
8389 | } | ||
8385 | auto assignment = x->new_ptr<ExpListAssign_t>(); | 8390 | auto assignment = x->new_ptr<ExpListAssign_t>(); |
8386 | assignment->expList.set(expList); | 8391 | assignment->expList.set(expList); |
8387 | assignment->action.set(assign); | 8392 | 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() { | |||
285 | ColonImportName = '\\' >> space >> Variable; | 285 | ColonImportName = '\\' >> space >> Variable; |
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 >> Exp; | 288 | ImportFrom = import_name_list >> *space_break >> space >> key("from") >> space >> (ImportLiteral | not_(String) >> Exp); |
289 | 289 | ||
290 | ImportLiteralInner = (range('a', 'z') | range('A', 'Z') | set("_-") | larger(255)) >> *(alpha_num | '-' | larger(255)); | 290 | ImportLiteralInner = (range('a', 'z') | range('A', 'Z') | set("_-") | larger(255)) >> *(alpha_num | '-' | larger(255)); |
291 | import_literal_chain = Seperator >> ImportLiteralInner >> *('.' >> ImportLiteralInner); | 291 | import_literal_chain = Seperator >> ImportLiteralInner >> *('.' >> ImportLiteralInner); |