aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLi Jin <dragon-fly@qq.com>2020-11-03 15:04:22 +0800
committerLi Jin <dragon-fly@qq.com>2020-11-03 15:04:22 +0800
commitf641df51ecec17dbd24b476e271a4ee49ed6aded (patch)
treef0a83f650a45037d33057dc913ca24ce04986dd3
parente07a2eb9c389f27103872a3b5a5bfe500d0c2d62 (diff)
downloadyuescript-f641df51ecec17dbd24b476e271a4ee49ed6aded.tar.gz
yuescript-f641df51ecec17dbd24b476e271a4ee49ed6aded.tar.bz2
yuescript-f641df51ecec17dbd24b476e271a4ee49ed6aded.zip
fix issue #30
-rw-r--r--spec/inputs/tables.mp16
-rw-r--r--src/MoonP/moon_ast.h2
-rw-r--r--src/MoonP/moon_compiler.cpp3
-rw-r--r--src/MoonP/moon_parser.cpp2
4 files changed, 20 insertions, 3 deletions
diff --git a/spec/inputs/tables.mp b/spec/inputs/tables.mp
index e816003..2c6dff9 100644
--- a/spec/inputs/tables.mp
+++ b/spec/inputs/tables.mp
@@ -203,5 +203,21 @@ items =
203 * [i for i = 1, 3] 203 * [i for i = 1, 3]
204 * "#{if a then b}" 204 * "#{if a then b}"
205 205
206pairs =
207 *
208 * "king"
209 * "queen"
210 *
211 * "hero"
212 * "princess"
213
214items =
215 *
216 name: "ring"
217 amount: 2
218 *
219 name: "necklace"
220 amount: 1
221
206nil 222nil
207 223
diff --git a/src/MoonP/moon_ast.h b/src/MoonP/moon_ast.h
index 02428ca..830234d 100644
--- a/src/MoonP/moon_ast.h
+++ b/src/MoonP/moon_ast.h
@@ -549,7 +549,7 @@ AST_END(TableBlockIndent)
549 549
550AST_NODE(TableBlock) 550AST_NODE(TableBlock)
551 ast_ptr<true, Seperator_t> sep; 551 ast_ptr<true, Seperator_t> sep;
552 ast_sel_list<false, variable_pair_t, normal_pair_t, TableBlockIndent_t, Exp_t> values; 552 ast_sel_list<false, variable_pair_t, normal_pair_t, TableBlockIndent_t, Exp_t, TableBlock_t> values;
553 AST_MEMBER(TableBlock, &sep, &values) 553 AST_MEMBER(TableBlock, &sep, &values)
554AST_END(TableBlock) 554AST_END(TableBlock)
555 555
diff --git a/src/MoonP/moon_compiler.cpp b/src/MoonP/moon_compiler.cpp
index 138a6bf..6fdaa3c 100644
--- a/src/MoonP/moon_compiler.cpp
+++ b/src/MoonP/moon_compiler.cpp
@@ -53,7 +53,7 @@ inline std::string s(std::string_view sv) {
53 return std::string(sv); 53 return std::string(sv);
54} 54}
55 55
56const std::string_view version = "0.4.20"sv; 56const std::string_view version = "0.4.21"sv;
57const std::string_view extension = "mp"sv; 57const std::string_view extension = "mp"sv;
58 58
59class MoonCompilerImpl { 59class MoonCompilerImpl {
@@ -4785,6 +4785,7 @@ private:
4785 case id<variable_pair_t>(): transform_variable_pair(static_cast<variable_pair_t*>(pair), temp); break; 4785 case id<variable_pair_t>(): transform_variable_pair(static_cast<variable_pair_t*>(pair), temp); break;
4786 case id<normal_pair_t>(): transform_normal_pair(static_cast<normal_pair_t*>(pair), temp); break; 4786 case id<normal_pair_t>(): transform_normal_pair(static_cast<normal_pair_t*>(pair), temp); break;
4787 case id<TableBlockIndent_t>(): transformTableBlockIndent(static_cast<TableBlockIndent_t*>(pair), temp); break; 4787 case id<TableBlockIndent_t>(): transformTableBlockIndent(static_cast<TableBlockIndent_t*>(pair), temp); break;
4788 case id<TableBlock_t>(): transformTableBlock(static_cast<TableBlock_t*>(pair), temp); break;
4788 default: assert(false); break; 4789 default: assert(false); break;
4789 } 4790 }
4790 temp.back() = indent() + temp.back() + (pair == pairs.back() ? Empty : s(","sv)) + nll(pair); 4791 temp.back() = indent() + temp.back() + (pair == pairs.back() ? Empty : s(","sv)) + nll(pair);
diff --git a/src/MoonP/moon_parser.cpp b/src/MoonP/moon_parser.cpp
index 63eabb3..8b9ead4 100644
--- a/src/MoonP/moon_parser.cpp
+++ b/src/MoonP/moon_parser.cpp
@@ -489,7 +489,7 @@ MoonParser::MoonParser() {
489 KeyValue = variable_pair | normal_pair; 489 KeyValue = variable_pair | normal_pair;
490 490
491 KeyValueList = KeyValue >> *(sym(',') >> KeyValue); 491 KeyValueList = KeyValue >> *(sym(',') >> KeyValue);
492 KeyValueLine = CheckIndent >> (KeyValueList >> -sym(',') | TableBlockIndent | Space >> expr('*') >> Exp); 492 KeyValueLine = CheckIndent >> (KeyValueList >> -sym(',') | TableBlockIndent | Space >> expr('*') >> (Exp | TableBlock));
493 493
494 FnArgDef = (Variable | SelfName) >> -(sym('=') >> Space >> Exp); 494 FnArgDef = (Variable | SelfName) >> -(sym('=') >> Space >> Exp);
495 495