From eba73a696c65932534fd5aefbe2ca4c7260c0fb6 Mon Sep 17 00:00:00 2001 From: Li Jin Date: Thu, 20 Aug 2020 09:46:49 +0800 Subject: reserve the same Moonscript coma separated expressions behaviors. --- spec/inputs/syntax.moon | 22 +++++++++++----------- spec/inputs/whitespace.moon | 42 +++++++++++++++++++++--------------------- src/MoonP/moon_compiler.cpp | 2 +- src/MoonP/moon_parser.cpp | 21 +++++++++++---------- src/MoonP/moon_parser.h | 1 + 5 files changed, 45 insertions(+), 43 deletions(-) diff --git a/spec/inputs/syntax.moon b/spec/inputs/syntax.moon index 9895c44..4435a1e 100644 --- a/spec/inputs/syntax.moon +++ b/spec/inputs/syntax.moon @@ -291,13 +291,13 @@ It's OK. func --[[port]] 3000, --[[ip]] "192.168.1.1" f = -> - a,b, - c,d, + a,b, \ + c,d, \ e,f f = -> - a,b - ,c,d + a,b \ + ,c,d \ ,e,f with obj @@ -369,13 +369,13 @@ do a = f2! - 1 |> f2 - _1 - ,_2 - ,_3 - ,_4 = 1 - ,f 2 - ,3 - ,f 4, + _1 \ + ,_2 \ + ,_3 \ + ,_4 = 1 \ + ,f 2 \ + ,3 \ + ,f 4, \ 4 nil diff --git a/spec/inputs/whitespace.moon b/spec/inputs/whitespace.moon index 06ce4eb..329280f 100644 --- a/spec/inputs/whitespace.moon +++ b/spec/inputs/whitespace.moon @@ -100,41 +100,41 @@ c(one, two, -- v = -> - a, -- v1 - b, -- v2 + a, \-- v1 + b, \-- v2 c -- v3 -v1, v2, +v1, v2, \ v3 = -> - a; -- end of function for v1 - b, -- v2 + a; \-- end of function for v1 + b, \-- v2 c -- v3 -a, b, - c, d, -e, f = 1, +a, b, \ + c, d, \ +e, f = 1, \ f2 - :abc; -- arg2 - 3, - 4, - f5 abc; -- arg5 + :abc; \-- arg2 + 3, \ + 4, \ + f5 abc; \-- arg5 6 -for a, -- destruct 1 - b, -- destruct 2 - --[[destruct 3]] c +for a, \-- destruct 1 + b, \-- destruct 2 + --[[destruct 3]] c \ in pairs tb - print a, - b, + print a, \ + b, \ c -for i = 1, -- initial - 10, -- stop +for i = 1, \-- initial + 10, \-- stop -1 -- step print i -local a, - b, +local a,\ + b,\ c nil diff --git a/src/MoonP/moon_compiler.cpp b/src/MoonP/moon_compiler.cpp index cac4ad0..2f16fff 100644 --- a/src/MoonP/moon_compiler.cpp +++ b/src/MoonP/moon_compiler.cpp @@ -49,7 +49,7 @@ inline std::string s(std::string_view sv) { } const std::string_view version() { - return "0.4.9"sv; + return "0.4.10"sv; } // name of table stored in lua registry diff --git a/src/MoonP/moon_parser.cpp b/src/MoonP/moon_parser.cpp index d30d6b5..a13a779 100644 --- a/src/MoonP/moon_parser.cpp +++ b/src/MoonP/moon_parser.cpp @@ -43,7 +43,8 @@ MoonParser::MoonParser() { multi_line_close = expr("]]"); multi_line_content = *(not_(multi_line_close) >> Any); MultiLineComment = multi_line_open >> multi_line_content >> multi_line_close; - space_one = set(" \t") | MultiLineComment; + EscapeNewLine = expr('\\') >> *(set(" \t") | MultiLineComment) >> -Comment >> Break; + space_one = set(" \t") | and_(set("-\\")) >> (MultiLineComment | EscapeNewLine); Space = *space_one >> -Comment; SpaceBreak = Space >> Break; White = Space >> *(Break >> Space); @@ -241,8 +242,8 @@ MoonParser::MoonParser() { While = key("while") >> DisableDo >> ensure(Exp, PopDo) >> -key("do") >> Body; Repeat = key("repeat") >> Body >> Break >> *EmptyLine >> CheckIndent >> key("until") >> Exp; - for_step_value = sym(',') >> White >> Exp; - for_args = Space >> Variable >> sym('=') >> Exp >> sym(',') >> White >> Exp >> -for_step_value; + for_step_value = sym(',') >> Exp; + for_args = Space >> Variable >> sym('=') >> Exp >> sym(',') >> Exp >> -for_step_value; For = key("for") >> DisableDo >> ensure(for_args, PopDo) >> @@ -250,7 +251,7 @@ MoonParser::MoonParser() { for_in = star_exp | ExpList; - ForEach = key("for") >> AssignableNameList >> White >> key("in") >> + ForEach = key("for") >> AssignableNameList >> key("in") >> DisableDo >> ensure(for_in, PopDo) >> -key("do") >> Body; @@ -278,10 +279,10 @@ MoonParser::MoonParser() { CompInner = Seperator >> (CompForEach | CompFor) >> *CompClause; star_exp = sym('*') >> Exp; CompForEach = key("for") >> AssignableNameList >> key("in") >> (star_exp | Exp); - CompFor = key("for") >> Space >> Variable >> sym('=') >> Exp >> sym(',') >> White >> Exp >> -for_step_value; + CompFor = key("for") >> Space >> Variable >> sym('=') >> Exp >> sym(',') >> Exp >> -for_step_value; CompClause = CompFor | CompForEach | key("when") >> Exp; - Assign = sym('=') >> Seperator >> (With | If | Switch | TableBlock | Exp >> *(White >> set(",;") >> White >> Exp)); + Assign = sym('=') >> Seperator >> (With | If | Switch | TableBlock | Exp >> *(Space >> set(",;") >> Exp)); update_op = expr("..") | @@ -514,15 +515,15 @@ MoonParser::MoonParser() { MacroLit = -macro_args_def >> Space >> expr("->") >> Body; Macro = key("macro") >> Space >> macro_type >> Space >> Name >> sym('=') >> MacroLit; - NameList = Seperator >> Space >> Variable >> *(sym(',') >> White >> Variable); + NameList = Seperator >> Space >> Variable >> *(sym(',') >> Space >> Variable); NameOrDestructure = Space >> Variable | TableLit; - AssignableNameList = Seperator >> NameOrDestructure >> *(sym(',') >> White >> NameOrDestructure); + AssignableNameList = Seperator >> NameOrDestructure >> *(sym(',') >> NameOrDestructure); fn_arrow_back = expr('<') >> set("-="); Backcall = -FnArgsDef >> Space >> fn_arrow_back >> Space >> ChainValue; - ExpList = Seperator >> Exp >> *(White >> expr(',') >> White >> Exp); - ExpListLow = Seperator >> Exp >> *(White >> set(",;") >> White >> Exp); + ExpList = Seperator >> Exp >> *(sym(',') >> Exp); + ExpListLow = Seperator >> Exp >> *(Space >> set(",;") >> Exp); ArgLine = CheckIndent >> Exp >> *(sym(',') >> Exp); ArgBlock = ArgLine >> *(sym(',') >> SpaceBreak >> ArgLine) >> PopIndent; diff --git a/src/MoonP/moon_parser.h b/src/MoonP/moon_parser.h index d7fa24b..c6a03f8 100644 --- a/src/MoonP/moon_parser.h +++ b/src/MoonP/moon_parser.h @@ -111,6 +111,7 @@ private: rule multi_line_content; rule MultiLineComment; rule Indent; + rule EscapeNewLine; rule space_one; rule Space; rule SpaceBreak; -- cgit v1.2.3-55-g6feb