diff options
author | Li Jin <dragon-fly@qq.com> | 2020-04-24 16:17:44 +0800 |
---|---|---|
committer | Li Jin <dragon-fly@qq.com> | 2020-04-24 16:17:44 +0800 |
commit | feac3c1cba6ca95b911240217f74a494680cd057 (patch) | |
tree | e85b6648a51c3355181bd1ad86f3a043c5223ee2 | |
parent | ade971c9b5f5d367de72ab8e65e9c651ce87cc9a (diff) | |
download | yuescript-feac3c1cba6ca95b911240217f74a494680cd057.tar.gz yuescript-feac3c1cba6ca95b911240217f74a494680cd057.tar.bz2 yuescript-feac3c1cba6ca95b911240217f74a494680cd057.zip |
fix errors when explicitly declaring global or local variable initialized with table block.
-rw-r--r-- | spec/inputs/plus.moon | 18 | ||||
-rw-r--r-- | src/MoonP/moon_ast.h | 5 | ||||
-rw-r--r-- | src/MoonP/moon_compiler.cpp | 16 | ||||
-rw-r--r-- | src/MoonP/moon_parser.cpp | 4 |
4 files changed, 36 insertions, 7 deletions
diff --git a/spec/inputs/plus.moon b/spec/inputs/plus.moon index f455845..38d3a08 100644 --- a/spec/inputs/plus.moon +++ b/spec/inputs/plus.moon | |||
@@ -17,3 +17,21 @@ valB = do | |||
17 | func = getfunc! | 17 | func = getfunc! |
18 | func?! | 18 | func?! |
19 | 19 | ||
20 | global backpack = | ||
21 | something: | ||
22 | yeah: 200 | ||
23 | they: -> | ||
24 | print "hello" | ||
25 | yor_feet"small" | ||
26 | pretty: hair | ||
27 | gold: hmm | ||
28 | yow: 1000 | ||
29 | |||
30 | eat: goo | ||
31 | yeah: dudd | ||
32 | |||
33 | start = | ||
34 | something: "cold" | ||
35 | |||
36 | local bathe = | ||
37 | on: "fire" | ||
diff --git a/src/MoonP/moon_ast.h b/src/MoonP/moon_ast.h index 44a55a4..7ef25a9 100644 --- a/src/MoonP/moon_ast.h +++ b/src/MoonP/moon_ast.h | |||
@@ -98,10 +98,11 @@ AST_NODE(NameList) | |||
98 | AST_END(NameList) | 98 | AST_END(NameList) |
99 | 99 | ||
100 | class ExpListLow_t; | 100 | class ExpListLow_t; |
101 | class TableBlock_t; | ||
101 | 102 | ||
102 | AST_NODE(local_values) | 103 | AST_NODE(local_values) |
103 | ast_ptr<true, NameList_t> nameList; | 104 | ast_ptr<true, NameList_t> nameList; |
104 | ast_ptr<false, ExpListLow_t> valueList; | 105 | ast_sel<false, TableBlock_t, ExpListLow_t> valueList; |
105 | AST_MEMBER(local_values, &nameList, &valueList) | 106 | AST_MEMBER(local_values, &nameList, &valueList) |
106 | AST_END(local_values) | 107 | AST_END(local_values) |
107 | 108 | ||
@@ -533,7 +534,7 @@ AST_END(ClassDecl) | |||
533 | 534 | ||
534 | AST_NODE(global_values) | 535 | AST_NODE(global_values) |
535 | ast_ptr<true, NameList_t> nameList; | 536 | ast_ptr<true, NameList_t> nameList; |
536 | ast_ptr<false, ExpListLow_t> valueList; | 537 | ast_sel<false, TableBlock_t, ExpListLow_t> valueList; |
537 | AST_MEMBER(global_values, &nameList, &valueList) | 538 | AST_MEMBER(global_values, &nameList, &valueList) |
538 | AST_END(global_values) | 539 | AST_END(global_values) |
539 | 540 | ||
diff --git a/src/MoonP/moon_compiler.cpp b/src/MoonP/moon_compiler.cpp index 80ab5a9..c9d9c78 100644 --- a/src/MoonP/moon_compiler.cpp +++ b/src/MoonP/moon_compiler.cpp | |||
@@ -43,7 +43,7 @@ inline std::string s(std::string_view sv) { | |||
43 | } | 43 | } |
44 | 44 | ||
45 | const std::string_view version() { | 45 | const std::string_view version() { |
46 | return "0.3.9"sv; | 46 | return "0.3.10"sv; |
47 | } | 47 | } |
48 | 48 | ||
49 | // name of table stored in lua registry | 49 | // name of table stored in lua registry |
@@ -4364,7 +4364,12 @@ private: | |||
4364 | auto assignment = x->new_ptr<ExpListAssign_t>(); | 4364 | auto assignment = x->new_ptr<ExpListAssign_t>(); |
4365 | assignment->expList.set(expList); | 4365 | assignment->expList.set(expList); |
4366 | auto assign = x->new_ptr<Assign_t>(); | 4366 | auto assign = x->new_ptr<Assign_t>(); |
4367 | assign->values.dup(values->valueList->exprs); | 4367 | if (auto expListLow = values->valueList.as<ExpListLow_t>()) { |
4368 | assign->values.dup(expListLow->exprs); | ||
4369 | } else { | ||
4370 | auto tableBlock = values->valueList.to<TableBlock_t>(); | ||
4371 | assign->values.push_back(tableBlock); | ||
4372 | } | ||
4368 | assignment->action.set(assign); | 4373 | assignment->action.set(assign); |
4369 | transformAssignment(assignment, out); | 4374 | transformAssignment(assignment, out); |
4370 | } else { | 4375 | } else { |
@@ -4993,7 +4998,12 @@ private: | |||
4993 | auto assignment = x->new_ptr<ExpListAssign_t>(); | 4998 | auto assignment = x->new_ptr<ExpListAssign_t>(); |
4994 | assignment->expList.set(expList); | 4999 | assignment->expList.set(expList); |
4995 | auto assign = x->new_ptr<Assign_t>(); | 5000 | auto assign = x->new_ptr<Assign_t>(); |
4996 | assign->values.dup(values->valueList->exprs); | 5001 | if (auto expListLow = values->valueList.as<ExpListLow_t>()) { |
5002 | assign->values.dup(expListLow->exprs); | ||
5003 | } else { | ||
5004 | auto tableBlock = values->valueList.to<TableBlock_t>(); | ||
5005 | assign->values.push_back(tableBlock); | ||
5006 | } | ||
4997 | assignment->action.set(assign); | 5007 | assignment->action.set(assign); |
4998 | transformAssignment(assignment, temp); | 5008 | transformAssignment(assignment, temp); |
4999 | } | 5009 | } |
diff --git a/src/MoonP/moon_parser.cpp b/src/MoonP/moon_parser.cpp index 9208d3a..7de2a84 100644 --- a/src/MoonP/moon_parser.cpp +++ b/src/MoonP/moon_parser.cpp | |||
@@ -170,7 +170,7 @@ MoonParser::MoonParser() { | |||
170 | InBlock = Advance >> ensure(Block, PopIndent); | 170 | InBlock = Advance >> ensure(Block, PopIndent); |
171 | 171 | ||
172 | local_flag = expr('*') | expr('^'); | 172 | local_flag = expr('*') | expr('^'); |
173 | local_values = NameList >> -(sym('=') >> ExpListLow); | 173 | local_values = NameList >> -(sym('=') >> (TableBlock | ExpListLow)); |
174 | Local = key("local") >> (Space >> local_flag | local_values); | 174 | Local = key("local") >> (Space >> local_flag | local_values); |
175 | 175 | ||
176 | colon_import_name = sym('\\') >> Space >> Variable; | 176 | colon_import_name = sym('\\') >> Space >> Variable; |
@@ -419,7 +419,7 @@ MoonParser::MoonParser() { | |||
419 | -(key("extends") >> PreventIndent >> ensure(Exp, PopIndent)) >> | 419 | -(key("extends") >> PreventIndent >> ensure(Exp, PopIndent)) >> |
420 | -ClassBlock; | 420 | -ClassBlock; |
421 | 421 | ||
422 | global_values = NameList >> -(sym('=') >> ExpListLow); | 422 | global_values = NameList >> -(sym('=') >> (TableBlock | ExpListLow)); |
423 | global_op = expr('*') | expr('^'); | 423 | global_op = expr('*') | expr('^'); |
424 | Global = key("global") >> (ClassDecl | (Space >> global_op) | global_values); | 424 | Global = key("global") >> (ClassDecl | (Space >> global_op) | global_values); |
425 | 425 | ||