From d8901102a1e39e651b08b66257c176b5803b9bc0 Mon Sep 17 00:00:00 2001 From: Li Jin Date: Mon, 3 Feb 2020 11:25:11 +0800 Subject: enable explist to be multi-line without backslash. confirmed there is no similar issue like Moonscript issue 202 or issue 391. --- spec/inputs/assign.moon | 3 +-- spec/inputs/destructure.moon | 9 +++++++++ spec/inputs/syntax.moon | 9 +++++++-- src/MoonP/moon_parser.cpp | 9 ++++----- src/MoonP/moon_parser.h | 1 - 5 files changed, 21 insertions(+), 10 deletions(-) diff --git a/spec/inputs/assign.moon b/spec/inputs/assign.moon index 4e50147..e8fcbfd 100644 --- a/spec/inputs/assign.moon +++ b/spec/inputs/assign.moon @@ -26,5 +26,4 @@ else print "the other" "nothing", "yeah" - - +c, d = 1, 2 if true diff --git a/spec/inputs/destructure.moon b/spec/inputs/destructure.moon index e0f2198..d61b6ae 100644 --- a/spec/inputs/destructure.moon +++ b/spec/inputs/destructure.moon @@ -103,3 +103,12 @@ do do {if:{a,b,c}} = thing + +do + {:a, :b} = {a: "Hello", b: "World"} if true + + {days, hours, mins, secs} = [tonumber a for a in *{ + string.match "1 2 3 4", "(.+)%s(.+)%s(.+)%s(.+)" + }] + + {:one, :two, :three} = {w,true for w in foo\gmatch("%S+")} diff --git a/spec/inputs/syntax.moon b/spec/inputs/syntax.moon index abee3e3..ae3fc0c 100644 --- a/spec/inputs/syntax.moon +++ b/spec/inputs/syntax.moon @@ -281,10 +281,15 @@ 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 \ + ,e,f + with obj invoke \ --[[arg1]] \func!, diff --git a/src/MoonP/moon_parser.cpp b/src/MoonP/moon_parser.cpp index 358b660..0ea6e12 100644 --- a/src/MoonP/moon_parser.cpp +++ b/src/MoonP/moon_parser.cpp @@ -45,7 +45,6 @@ MoonParser::MoonParser() { MultiLineComment = multi_line_open >> multi_line_content >> multi_line_close; EscapeNewLine = expr('\\') >> *(set(" \t") | MultiLineComment) >> -Comment >> Break; Space = *(set(" \t") | MultiLineComment | EscapeNewLine) >> -Comment; - SomeSpace = +set(" \t") >> -Comment; SpaceBreak = Space >> Break; EmptyLine = SpaceBreak; AlphaNum = range('a', 'z') | range('A', 'Z') | range('0', '9') | '_'; @@ -396,7 +395,7 @@ MoonParser::MoonParser() { export_op = expr('*') | expr('^'); Export = key("export") >> (ClassDecl | (Space >> export_op) | export_values); - variable_pair = sym(':') >> not_(SomeSpace) >> Space >> Variable; + variable_pair = sym(':') >> Variable; normal_pair = ( KeyName | @@ -436,8 +435,8 @@ MoonParser::MoonParser() { Backcall = -FnArgsDef >> Space >> symx("<-") >> Space >> ChainValue; - ExpList = Seperator >> Exp >> *(sym(',') >> Exp); - ExpListLow = Seperator >> Exp >> *((sym(',') | sym(';')) >> Exp); + ExpList = Seperator >> Exp >> *(sym(',') >> White >> Exp); + ExpListLow = Seperator >> Exp >> *((sym(',') | sym(';')) >> White >> Exp); ArgLine = CheckIndent >> Exp >> *(sym(',') >> Exp); ArgBlock = ArgLine >> *(sym(',') >> SpaceBreak >> ArgLine) >> PopIndent; @@ -457,7 +456,7 @@ MoonParser::MoonParser() { ); const_value = (expr("nil") | expr("true") | expr("false")) >> not_(AlphaNum); - minus_exp = expr('-') >> not_(SomeSpace) >> Exp; + minus_exp = expr('-') >> not_(set(" \t")) >> Exp; sharp_exp = expr('#') >> Exp; tilde_exp = expr('~') >> Exp; not_exp = expr("not") >> not_(AlphaNum) >> Exp; diff --git a/src/MoonP/moon_parser.h b/src/MoonP/moon_parser.h index a0ad2fa..2107a14 100644 --- a/src/MoonP/moon_parser.h +++ b/src/MoonP/moon_parser.h @@ -107,7 +107,6 @@ private: rule Indent; rule EscapeNewLine; rule Space; - rule SomeSpace; rule SpaceBreak; rule EmptyLine; rule AlphaNum; -- cgit v1.2.3-55-g6feb