aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLi Jin <dragon-fly@qq.com>2020-08-06 12:11:01 +0800
committerLi Jin <dragon-fly@qq.com>2020-08-06 12:11:01 +0800
commitacf20e1802b03fed63b845ac8c0274fff415fb22 (patch)
treef8410fa73f59ee31814e3b24dc9ec7a959a5a706
parentcb5371a7dcfde196db07f5a2a3f144888b73d522 (diff)
downloadyuescript-acf20e1802b03fed63b845ac8c0274fff415fb22.tar.gz
yuescript-acf20e1802b03fed63b845ac8c0274fff415fb22.tar.bz2
yuescript-acf20e1802b03fed63b845ac8c0274fff415fb22.zip
fix a case multiline binary operator expression conflicts with new statement started with an unary expression.
-rw-r--r--spec/inputs/syntax.moon23
-rw-r--r--src/MoonP/moon_compiler.cpp2
-rw-r--r--src/MoonP/moon_parser.cpp6
3 files changed, 27 insertions, 4 deletions
diff --git a/spec/inputs/syntax.moon b/spec/inputs/syntax.moon
index a781aa3..80b762c 100644
--- a/spec/inputs/syntax.moon
+++ b/spec/inputs/syntax.moon
@@ -346,5 +346,28 @@ v = {
346 a ~ --[[123]]1 346 a ~ --[[123]]1
347} 347}
348 348
349do
350 a = 1
351 + 2
352 * 3 /
353 4
354
355 _1 = f1 -1
356 + 2
357 + 3
358
359 _2 = f1 - 1
360 + 2
361 + 3
362
363 f2 = (x)-> print x
364 +1
365
366 a = f2!
367 -1 |> f2
368
369 a = f2!
370 - 1 |> f2
371
349nil 372nil
350 373
diff --git a/src/MoonP/moon_compiler.cpp b/src/MoonP/moon_compiler.cpp
index f517e27..1652e17 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
51const std::string_view version() { 51const std::string_view version() {
52 return "0.4.7"sv; 52 return "0.4.8"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 43e6887..6fa014f 100644
--- a/src/MoonP/moon_parser.cpp
+++ b/src/MoonP/moon_parser.cpp
@@ -308,9 +308,9 @@ MoonParser::MoonParser() {
308 expo_exp = Value >> *expo_value; 308 expo_exp = Value >> *expo_value;
309 309
310 unary_operator = 310 unary_operator =
311 expr('-') >> not_(expr('>') | space_one) | 311 expr('-') >> not_(set(">=") | space_one) |
312 expr('#') | 312 expr('#') |
313 expr('~') >> not_(space_one) | 313 expr('~') >> not_(expr('=') | space_one) |
314 expr("not") >> not_(AlphaNum); 314 expr("not") >> not_(AlphaNum);
315 unary_exp = *(Space >> unary_operator) >> expo_exp; 315 unary_exp = *(Space >> unary_operator) >> expo_exp;
316 316
@@ -331,7 +331,7 @@ MoonParser::MoonParser() {
331 expr(">>") | 331 expr(">>") |
332 expr("//") | 332 expr("//") |
333 set("+-*/%><|&~"); 333 set("+-*/%><|&~");
334 exp_op_value = White >> BinaryOperator >> *SpaceBreak >> backcall_exp; 334 exp_op_value = (White >> not_(unary_operator) | Space) >> BinaryOperator >> *SpaceBreak >> backcall_exp;
335 Exp = Seperator >> backcall_exp >> *exp_op_value; 335 Exp = Seperator >> backcall_exp >> *exp_op_value;
336 336
337 ChainValue = Seperator >> (Chain | Callable) >> -existential_op >> -InvokeArgs; 337 ChainValue = Seperator >> (Chain | Callable) >> -existential_op >> -InvokeArgs;