From cb5371a7dcfde196db07f5a2a3f144888b73d522 Mon Sep 17 00:00:00 2001 From: Li Jin Date: Thu, 6 Aug 2020 10:32:05 +0800 Subject: remove support for escape new line symbol, binary operator expressions can now be written multiline without escape new line symbol. --- CHANGELOG.md | 29 ++++++++--------------------- spec/inputs/backcall.moon | 8 ++++---- spec/inputs/syntax.moon | 41 ++++++++++++++++++++++------------------- src/MoonP/moon_compiler.cpp | 2 +- src/MoonP/moon_parser.cpp | 11 +++++------ src/MoonP/moon_parser.h | 1 - 6 files changed, 40 insertions(+), 52 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0154124..698921f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,10 +4,13 @@ The implementation for original Moonscript language 0.5.0 can be found in the `0 -## v0.4.4 +## v0.4.7 ### Fixed Issues +* Remove support for escape new line symbol, binary operator expressions can now be written multiline without escape new line symbol. +* Fix an issue when extending class without name. +* Fix an issue when using return with export statement. * Fix issues when declaring table key with Lua multiline string and indexing expressions with Lua multiline string. ### Added Features @@ -229,29 +232,13 @@ Fix issues in original Moonscript compiler: ### Added Features * Multi-line comment support. -* Usage for symbol `\` to escape new line. Will compile codes: -```Moonscript -str = --[[ - This is a multi line comment. - It's OK. -]] strA \ -- comment 1 - .. strB \ -- comment 2 - .. strC - -func --[[ip]] "192.168.126.110", --[[port]] 3000 -``` -  to: -```Lua -local str = strA .. strB .. strC -func("192.168.126.110", 3000) -``` * Back call features with new operator and syntax. For example: ```Moonscript -{1,2,3} \ - |> map((x)-> x * 2) \ - |> filter((x)-> x > 4) \ - |> reduce(0, (a,b)-> a + b) \ +{1,2,3} + |> map((x)-> x * 2) + |> filter((x)-> x > 4) + |> reduce(0, (a,b)-> a + b) |> print do diff --git a/spec/inputs/backcall.moon b/spec/inputs/backcall.moon index 86b0ba3..a648b16 100644 --- a/spec/inputs/backcall.moon +++ b/spec/inputs/backcall.moon @@ -1,10 +1,10 @@ {"abc", 123, 998} |> foreach print -{1,2,3} \ - |> map((x)-> x * 2) \ - |> filter((x)-> x > 4) \ - |> reduce(0, (a,b)-> a + b) \ +{1,2,3} + |> map((x)-> x * 2) + |> filter((x)-> x > 4) + |> reduce(0, (a,b)-> a + b) |> print [i |> tostring for i = 0,10] |> table.concat(",") |> print diff --git a/spec/inputs/syntax.moon b/spec/inputs/syntax.moon index ccee5f2..a781aa3 100644 --- a/spec/inputs/syntax.moon +++ b/spec/inputs/syntax.moon @@ -284,8 +284,8 @@ z = a- b str = --[[ This is a multi line comment. It's OK. -]] strA \ -- comment 1 - .. strB \ -- comment 2 +]] strA -- comment 1 + .. strB -- comment 2 .. strC func --[[port]] 3000, --[[ip]] "192.168.1.1" @@ -296,51 +296,54 @@ f = -> e,f f = -> - a,b \ - ,c,d \ + a,b + ,c,d ,e,f with obj - invoke \ + invoke( --[[arg1]] \func!, --[[arg2]] 123, --[[arg3]] "abc" + ) -invokeA \ - invokeB \ +invokeA( + invokeB( invokeC 123 + ) +) -123 \ - |> invokeC \ - |> invokeB \ +123 + |> invokeC + |> invokeB |> invokeA v = { a -1 - a\ --1 - a\ + a( +-1) + a - 1 a-1 a - 1 a - 1 - a -\ + a- 1 a - --[[123]]1 a ~1 - a\ -~1 - a\ + a( +~1) + a ~ 1 a~1 a ~ 1 a ~ 1 - a ~\ + a~ 1 - a ~--[[123]]1 + a ~ --[[123]]1 } nil diff --git a/src/MoonP/moon_compiler.cpp b/src/MoonP/moon_compiler.cpp index 6ce4e48..f517e27 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.6"sv; + return "0.4.7"sv; } // name of table stored in lua registry diff --git a/src/MoonP/moon_parser.cpp b/src/MoonP/moon_parser.cpp index df7d810..43e6887 100644 --- a/src/MoonP/moon_parser.cpp +++ b/src/MoonP/moon_parser.cpp @@ -43,8 +43,7 @@ MoonParser::MoonParser() { multi_line_close = expr("]]"); multi_line_content = *(not_(multi_line_close) >> Any); MultiLineComment = multi_line_open >> multi_line_content >> multi_line_close; - EscapeNewLine = expr('\\') >> *(set(" \t") | MultiLineComment) >> -Comment >> Break; - space_one = set(" \t") | and_(set("-\\")) >> (MultiLineComment | EscapeNewLine); + space_one = set(" \t") | MultiLineComment; Space = *space_one >> -Comment; SpaceBreak = Space >> Break; White = Space >> *(Break >> Space); @@ -316,7 +315,7 @@ MoonParser::MoonParser() { unary_exp = *(Space >> unary_operator) >> expo_exp; BackcallOperator = expr("|>"); - backcall_value = Space >> BackcallOperator >> *SpaceBreak >> unary_exp; + backcall_value = White >> BackcallOperator >> *SpaceBreak >> unary_exp; backcall_exp = unary_exp >> *backcall_value; BinaryOperator = @@ -332,7 +331,7 @@ MoonParser::MoonParser() { expr(">>") | expr("//") | set("+-*/%><|&~"); - exp_op_value = Space >> BinaryOperator >> *SpaceBreak >> backcall_exp; + exp_op_value = White >> BinaryOperator >> *SpaceBreak >> backcall_exp; Exp = Seperator >> backcall_exp >> *exp_op_value; ChainValue = Seperator >> (Chain | Callable) >> -existential_op >> -InvokeArgs; @@ -522,8 +521,8 @@ MoonParser::MoonParser() { fn_arrow_back = expr('<') >> set("-="); Backcall = -FnArgsDef >> Space >> fn_arrow_back >> Space >> ChainValue; - ExpList = Seperator >> Exp >> *(sym(',') >> White >> Exp); - ExpListLow = Seperator >> Exp >> *((sym(',') | sym(';')) >> White >> Exp); + ExpList = Seperator >> Exp >> *(White >> expr(',') >> White >> Exp); + ExpListLow = Seperator >> Exp >> *(White >> set(",;") >> White >> 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 c6a03f8..d7fa24b 100644 --- a/src/MoonP/moon_parser.h +++ b/src/MoonP/moon_parser.h @@ -111,7 +111,6 @@ private: rule multi_line_content; rule MultiLineComment; rule Indent; - rule EscapeNewLine; rule space_one; rule Space; rule SpaceBreak; -- cgit v1.2.3-55-g6feb