aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xdoc/docs/doc/README.md4
-rwxr-xr-xdoc/docs/zh/doc/README.md4
-rw-r--r--spec/inputs/import.yue4
-rw-r--r--spec/outputs/import.lua23
-rw-r--r--src/yuescript/yue_ast.cpp2
-rw-r--r--src/yuescript/yue_ast.h4
-rw-r--r--src/yuescript/yue_compiler.cpp11
-rw-r--r--src/yuescript/yue_parser.cpp2
8 files changed, 47 insertions, 7 deletions
diff --git a/doc/docs/doc/README.md b/doc/docs/doc/README.md
index 9b47d06..1087b9a 100755
--- a/doc/docs/doc/README.md
+++ b/doc/docs/doc/README.md
@@ -687,6 +687,8 @@ do
687 import insert, concat from table 687 import insert, concat from table
688 -- report error when assigning to insert, concat 688 -- report error when assigning to insert, concat
689 import C, Ct, Cmt from require "lpeg" 689 import C, Ct, Cmt from require "lpeg"
690 -- shortcut for implicit requiring
691 import x, y, z from 'mymodule'
690 692
691-- shortcut for requring a module 693-- shortcut for requring a module
692do 694do
@@ -708,6 +710,8 @@ do
708 import insert, concat from table 710 import insert, concat from table
709 -- report error when assigning to insert, concat 711 -- report error when assigning to insert, concat
710 import C, Ct, Cmt from require "lpeg" 712 import C, Ct, Cmt from require "lpeg"
713 -- shortcut for implicit requiring
714 import x, y, z from 'mymodule'
711 715
712-- shortcut for requring a module 716-- shortcut for requring a module
713do 717do
diff --git a/doc/docs/zh/doc/README.md b/doc/docs/zh/doc/README.md
index 3ae6af7..472ac15 100755
--- a/doc/docs/zh/doc/README.md
+++ b/doc/docs/zh/doc/README.md
@@ -685,6 +685,8 @@ do
685 import insert, concat from table 685 import insert, concat from table
686 -- 当给 insert, concat 变量赋值时,编译器会报告错误 686 -- 当给 insert, concat 变量赋值时,编译器会报告错误
687 import C, Ct, Cmt from require "lpeg" 687 import C, Ct, Cmt from require "lpeg"
688 -- 快捷写法引入模块的子项
689 import x, y, z from 'mymodule'
688 690
689-- 快捷地导入一个模块 691-- 快捷地导入一个模块
690do 692do
@@ -706,6 +708,8 @@ do
706 import insert, concat from table 708 import insert, concat from table
707 -- 当给 insert, concat 变量赋值时,编译器会报告错误 709 -- 当给 insert, concat 变量赋值时,编译器会报告错误
708 import C, Ct, Cmt from require "lpeg" 710 import C, Ct, Cmt from require "lpeg"
711 -- 快捷写法引入模块的子项
712 import x, y, z from 'mymodule'
709 713
710-- 快捷地导入一个模块 714-- 快捷地导入一个模块
711do 715do
diff --git a/spec/inputs/import.yue b/spec/inputs/import.yue
index 73e05d2..eb2a487 100644
--- a/spec/inputs/import.yue
+++ b/spec/inputs/import.yue
@@ -41,6 +41,10 @@ do
41 c 41 c
42 from z 42 from z
43 43
44do
45 import p from "yue"
46 import item from 'module.part'
47 import x1, y1, \z1 from "mymodule"
44 48
45do 49do
46 import 'module' 50 import 'module'
diff --git a/spec/outputs/import.lua b/spec/outputs/import.lua
index 02fe42a..b384d9d 100644
--- a/spec/outputs/import.lua
+++ b/spec/outputs/import.lua
@@ -57,6 +57,29 @@ do
57 local a, b, c = z.a, z.b, z.c 57 local a, b, c = z.a, z.b, z.c
58end 58end
59do 59do
60 local p
61 do
62 local _obj_1 = require("yue")
63 p = _obj_1.p
64 end
65 local item
66 do
67 local _obj_1 = require('module.part')
68 item = _obj_1.item
69 end
70 local x1, y1, z1
71 do
72 local _obj_1 = require("mymodule")
73 x1, y1, z1 = _obj_1.x1, _obj_1.y1, (function()
74 local _base_0 = _obj_1
75 local _fn_0 = _base_0.z1
76 return _fn_0 and function(...)
77 return _fn_0(_base_0, ...)
78 end
79 end)()
80 end
81end
82do
60 local module = require('module') 83 local module = require('module')
61 local module_x = require('module_x') 84 local module_x = require('module_x')
62 local d_a_s_h_e_s = require("d-a-s-h-e-s") 85 local d_a_s_h_e_s = require("d-a-s-h-e-s")
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}
274std::string MacroNamePair_t::to_string(void* ud) const { 274std::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)
191AST_NODE(ImportFrom) 191AST_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)
196AST_END(ImportFrom, "import_from"sv) 196AST_END(ImportFrom, "import_from"sv)
197 197
198AST_NODE(MacroNamePair) 198AST_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
77const std::string_view version = "0.19.2"sv; 77const std::string_view version = "0.19.3"sv;
78const std::string_view extension = "yue"sv; 78const std::string_view extension = "yue"sv;
79 79
80class CompileError : public std::logic_error { 80class 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);