diff options
author | Li Jin <dragon-fly@qq.com> | 2020-08-06 10:32:05 +0800 |
---|---|---|
committer | Li Jin <dragon-fly@qq.com> | 2020-08-06 10:32:05 +0800 |
commit | cb5371a7dcfde196db07f5a2a3f144888b73d522 (patch) | |
tree | 65d7a5d031b83a78f3d3e00725dc15b4bfda2176 | |
parent | 2506c1b429e952245295e54e71dac4b345e88984 (diff) | |
download | yuescript-cb5371a7dcfde196db07f5a2a3f144888b73d522.tar.gz yuescript-cb5371a7dcfde196db07f5a2a3f144888b73d522.tar.bz2 yuescript-cb5371a7dcfde196db07f5a2a3f144888b73d522.zip |
remove support for escape new line symbol, binary operator expressions can now be written multiline without escape new line symbol.
-rw-r--r-- | CHANGELOG.md | 29 | ||||
-rw-r--r-- | spec/inputs/backcall.moon | 8 | ||||
-rw-r--r-- | spec/inputs/syntax.moon | 41 | ||||
-rw-r--r-- | src/MoonP/moon_compiler.cpp | 2 | ||||
-rw-r--r-- | src/MoonP/moon_parser.cpp | 11 | ||||
-rw-r--r-- | 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 | |||
4 | 4 | ||
5 | 5 | ||
6 | 6 | ||
7 | ## v0.4.4 | 7 | ## v0.4.7 |
8 | 8 | ||
9 | ### Fixed Issues | 9 | ### Fixed Issues |
10 | 10 | ||
11 | * Remove support for escape new line symbol, binary operator expressions can now be written multiline without escape new line symbol. | ||
12 | * Fix an issue when extending class without name. | ||
13 | * Fix an issue when using return with export statement. | ||
11 | * Fix issues when declaring table key with Lua multiline string and indexing expressions with Lua multiline string. | 14 | * Fix issues when declaring table key with Lua multiline string and indexing expressions with Lua multiline string. |
12 | 15 | ||
13 | ### Added Features | 16 | ### Added Features |
@@ -229,29 +232,13 @@ Fix issues in original Moonscript compiler: | |||
229 | ### Added Features | 232 | ### Added Features |
230 | 233 | ||
231 | * Multi-line comment support. | 234 | * Multi-line comment support. |
232 | * Usage for symbol `\` to escape new line. Will compile codes: | ||
233 | ```Moonscript | ||
234 | str = --[[ | ||
235 | This is a multi line comment. | ||
236 | It's OK. | ||
237 | ]] strA \ -- comment 1 | ||
238 | .. strB \ -- comment 2 | ||
239 | .. strC | ||
240 | |||
241 | func --[[ip]] "192.168.126.110", --[[port]] 3000 | ||
242 | ``` | ||
243 |   to: | ||
244 | ```Lua | ||
245 | local str = strA .. strB .. strC | ||
246 | func("192.168.126.110", 3000) | ||
247 | ``` | ||
248 | 235 | ||
249 | * Back call features with new operator and syntax. For example: | 236 | * Back call features with new operator and syntax. For example: |
250 | ```Moonscript | 237 | ```Moonscript |
251 | {1,2,3} \ | 238 | {1,2,3} |
252 | |> map((x)-> x * 2) \ | 239 | |> map((x)-> x * 2) |
253 | |> filter((x)-> x > 4) \ | 240 | |> filter((x)-> x > 4) |
254 | |> reduce(0, (a,b)-> a + b) \ | 241 | |> reduce(0, (a,b)-> a + b) |
255 | 242 | ||
256 | 243 | ||
257 | do | 244 | 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 @@ | |||
1 | 1 | ||
2 | {"abc", 123, 998} |> foreach print | 2 | {"abc", 123, 998} |> foreach print |
3 | 3 | ||
4 | {1,2,3} \ | 4 | {1,2,3} |
5 | |> map((x)-> x * 2) \ | 5 | |> map((x)-> x * 2) |
6 | |> filter((x)-> x > 4) \ | 6 | |> filter((x)-> x > 4) |
7 | |> reduce(0, (a,b)-> a + b) \ | 7 | |> reduce(0, (a,b)-> a + b) |
8 | 8 | ||
9 | 9 | ||
10 | [i |> tostring for i = 0,10] |> table.concat(",") |> print | 10 | [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 | |||
284 | str = --[[ | 284 | str = --[[ |
285 | This is a multi line comment. | 285 | This is a multi line comment. |
286 | It's OK. | 286 | It's OK. |
287 | ]] strA \ -- comment 1 | 287 | ]] strA -- comment 1 |
288 | .. strB \ -- comment 2 | 288 | .. strB -- comment 2 |
289 | .. strC | 289 | .. strC |
290 | 290 | ||
291 | func --[[port]] 3000, --[[ip]] "192.168.1.1" | 291 | func --[[port]] 3000, --[[ip]] "192.168.1.1" |
@@ -296,51 +296,54 @@ f = -> | |||
296 | e,f | 296 | e,f |
297 | 297 | ||
298 | f = -> | 298 | f = -> |
299 | a,b \ | 299 | a,b |
300 | ,c,d \ | 300 | ,c,d |
301 | ,e,f | 301 | ,e,f |
302 | 302 | ||
303 | with obj | 303 | with obj |
304 | invoke \ | 304 | invoke( |
305 | --[[arg1]] \func!, | 305 | --[[arg1]] \func!, |
306 | --[[arg2]] 123, | 306 | --[[arg2]] 123, |
307 | --[[arg3]] "abc" | 307 | --[[arg3]] "abc" |
308 | ) | ||
308 | 309 | ||
309 | invokeA \ | 310 | invokeA( |
310 | invokeB \ | 311 | invokeB( |
311 | invokeC 123 | 312 | invokeC 123 |
313 | ) | ||
314 | ) | ||
312 | 315 | ||
313 | 123 \ | 316 | 123 |
314 | |> invokeC \ | 317 | |> invokeC |
315 | |> invokeB \ | 318 | |> invokeB |
316 | |> invokeA | 319 | |> invokeA |
317 | 320 | ||
318 | v = { | 321 | v = { |
319 | a -1 | 322 | a -1 |
320 | a\ | 323 | a( |
321 | -1 | 324 | -1) |
322 | a\ | 325 | a |
323 | - 1 | 326 | - 1 |
324 | a-1 | 327 | a-1 |
325 | a - 1 | 328 | a - 1 |
326 | a - | 329 | a - |
327 | 1 | 330 | 1 |
328 | a -\ | 331 | a- |
329 | 1 | 332 | 1 |
330 | a - --[[123]]1 | 333 | a - --[[123]]1 |
331 | 334 | ||
332 | a ~1 | 335 | a ~1 |
333 | a\ | 336 | a( |
334 | ~1 | 337 | ~1) |
335 | a\ | 338 | a |
336 | ~ 1 | 339 | ~ 1 |
337 | a~1 | 340 | a~1 |
338 | a ~ 1 | 341 | a ~ 1 |
339 | a ~ | 342 | a ~ |
340 | 1 | 343 | 1 |
341 | a ~\ | 344 | a~ |
342 | 1 | 345 | 1 |
343 | a ~--[[123]]1 | 346 | a ~ --[[123]]1 |
344 | } | 347 | } |
345 | 348 | ||
346 | nil | 349 | 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) { | |||
49 | } | 49 | } |
50 | 50 | ||
51 | const std::string_view version() { | 51 | const std::string_view version() { |
52 | return "0.4.6"sv; | 52 | return "0.4.7"sv; |
53 | } | 53 | } |
54 | 54 | ||
55 | // name of table stored in lua registry | 55 | // 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() { | |||
43 | multi_line_close = expr("]]"); | 43 | multi_line_close = expr("]]"); |
44 | multi_line_content = *(not_(multi_line_close) >> Any); | 44 | multi_line_content = *(not_(multi_line_close) >> Any); |
45 | MultiLineComment = multi_line_open >> multi_line_content >> multi_line_close; | 45 | MultiLineComment = multi_line_open >> multi_line_content >> multi_line_close; |
46 | EscapeNewLine = expr('\\') >> *(set(" \t") | MultiLineComment) >> -Comment >> Break; | 46 | space_one = set(" \t") | MultiLineComment; |
47 | space_one = set(" \t") | and_(set("-\\")) >> (MultiLineComment | EscapeNewLine); | ||
48 | Space = *space_one >> -Comment; | 47 | Space = *space_one >> -Comment; |
49 | SpaceBreak = Space >> Break; | 48 | SpaceBreak = Space >> Break; |
50 | White = Space >> *(Break >> Space); | 49 | White = Space >> *(Break >> Space); |
@@ -316,7 +315,7 @@ MoonParser::MoonParser() { | |||
316 | unary_exp = *(Space >> unary_operator) >> expo_exp; | 315 | unary_exp = *(Space >> unary_operator) >> expo_exp; |
317 | 316 | ||
318 | BackcallOperator = expr("|>"); | 317 | BackcallOperator = expr("|>"); |
319 | backcall_value = Space >> BackcallOperator >> *SpaceBreak >> unary_exp; | 318 | backcall_value = White >> BackcallOperator >> *SpaceBreak >> unary_exp; |
320 | backcall_exp = unary_exp >> *backcall_value; | 319 | backcall_exp = unary_exp >> *backcall_value; |
321 | 320 | ||
322 | BinaryOperator = | 321 | BinaryOperator = |
@@ -332,7 +331,7 @@ MoonParser::MoonParser() { | |||
332 | expr(">>") | | 331 | expr(">>") | |
333 | expr("//") | | 332 | expr("//") | |
334 | set("+-*/%><|&~"); | 333 | set("+-*/%><|&~"); |
335 | exp_op_value = Space >> BinaryOperator >> *SpaceBreak >> backcall_exp; | 334 | exp_op_value = White >> BinaryOperator >> *SpaceBreak >> backcall_exp; |
336 | Exp = Seperator >> backcall_exp >> *exp_op_value; | 335 | Exp = Seperator >> backcall_exp >> *exp_op_value; |
337 | 336 | ||
338 | ChainValue = Seperator >> (Chain | Callable) >> -existential_op >> -InvokeArgs; | 337 | ChainValue = Seperator >> (Chain | Callable) >> -existential_op >> -InvokeArgs; |
@@ -522,8 +521,8 @@ MoonParser::MoonParser() { | |||
522 | fn_arrow_back = expr('<') >> set("-="); | 521 | fn_arrow_back = expr('<') >> set("-="); |
523 | Backcall = -FnArgsDef >> Space >> fn_arrow_back >> Space >> ChainValue; | 522 | Backcall = -FnArgsDef >> Space >> fn_arrow_back >> Space >> ChainValue; |
524 | 523 | ||
525 | ExpList = Seperator >> Exp >> *(sym(',') >> White >> Exp); | 524 | ExpList = Seperator >> Exp >> *(White >> expr(',') >> White >> Exp); |
526 | ExpListLow = Seperator >> Exp >> *((sym(',') | sym(';')) >> White >> Exp); | 525 | ExpListLow = Seperator >> Exp >> *(White >> set(",;") >> White >> Exp); |
527 | 526 | ||
528 | ArgLine = CheckIndent >> Exp >> *(sym(',') >> Exp); | 527 | ArgLine = CheckIndent >> Exp >> *(sym(',') >> Exp); |
529 | ArgBlock = ArgLine >> *(sym(',') >> SpaceBreak >> ArgLine) >> PopIndent; | 528 | 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: | |||
111 | rule multi_line_content; | 111 | rule multi_line_content; |
112 | rule MultiLineComment; | 112 | rule MultiLineComment; |
113 | rule Indent; | 113 | rule Indent; |
114 | rule EscapeNewLine; | ||
115 | rule space_one; | 114 | rule space_one; |
116 | rule Space; | 115 | rule Space; |
117 | rule SpaceBreak; | 116 | rule SpaceBreak; |