From 5b656d2913e4f9f0017698ec835ce4ddda1dc81f Mon Sep 17 00:00:00 2001 From: Li Jin Date: Fri, 18 Sep 2020 17:24:03 +0800 Subject: support inserting common expression item started with * symbol into a table block. --- spec/inputs/tables.moon | 23 +++++++++++++++++++++++ src/MoonP/moon_ast.h | 2 +- src/MoonP/moon_compiler.cpp | 2 +- src/MoonP/moon_parser.cpp | 2 +- 4 files changed, 26 insertions(+), 3 deletions(-) diff --git a/spec/inputs/tables.moon b/spec/inputs/tables.moon index 6375660..e816003 100644 --- a/spec/inputs/tables.moon +++ b/spec/inputs/tables.moon @@ -180,5 +180,28 @@ heroine = * attribute: "mana" value: 100 +inventory = + equipment: + * "sword" + * "shield" + items: + * name: "potion" + count: 10 + * name: "bread" + count: 3 + +items = + * func! + * with tb + .abc = 123 + * {1, 2, 3} + * f {1, 2, 3} + * f + * 1 + * 2 + * 3 + * [i for i = 1, 3] + * "#{if a then b}" + nil diff --git a/src/MoonP/moon_ast.h b/src/MoonP/moon_ast.h index 16f7801..90508a5 100644 --- a/src/MoonP/moon_ast.h +++ b/src/MoonP/moon_ast.h @@ -535,7 +535,7 @@ AST_END(TableBlockIndent) AST_NODE(TableBlock) ast_ptr sep; - ast_sel_list values; + ast_sel_list values; AST_MEMBER(TableBlock, &sep, &values) AST_END(TableBlock) diff --git a/src/MoonP/moon_compiler.cpp b/src/MoonP/moon_compiler.cpp index 510b47e..8c0746f 100644 --- a/src/MoonP/moon_compiler.cpp +++ b/src/MoonP/moon_compiler.cpp @@ -54,7 +54,7 @@ inline std::string s(std::string_view sv) { } const std::string_view version() { - return "0.4.14"sv; + return "0.4.15"sv; } class MoonCompilerImpl { diff --git a/src/MoonP/moon_parser.cpp b/src/MoonP/moon_parser.cpp index 394ce50..41db324 100644 --- a/src/MoonP/moon_parser.cpp +++ b/src/MoonP/moon_parser.cpp @@ -491,7 +491,7 @@ MoonParser::MoonParser() { }); KeyValueList = KeyValue >> *(sym(',') >> KeyValue); - KeyValueLine = CheckIndent >> (KeyValueList >> -sym(',') | TableBlockIndent); + KeyValueLine = CheckIndent >> (KeyValueList >> -sym(',') | TableBlockIndent | Space >> expr('*') >> Exp); FnArgDef = (Variable | SelfName) >> -(sym('=') >> Space >> Exp); -- cgit v1.2.3-55-g6feb