From acf20e1802b03fed63b845ac8c0274fff415fb22 Mon Sep 17 00:00:00 2001 From: Li Jin Date: Thu, 6 Aug 2020 12:11:01 +0800 Subject: fix a case multiline binary operator expression conflicts with new statement started with an unary expression. --- spec/inputs/syntax.moon | 23 +++++++++++++++++++++++ src/MoonP/moon_compiler.cpp | 2 +- src/MoonP/moon_parser.cpp | 6 +++--- 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 = { a ~ --[[123]]1 } +do + a = 1 + + 2 + * 3 / + 4 + + _1 = f1 -1 + + 2 + + 3 + + _2 = f1 - 1 + + 2 + + 3 + + f2 = (x)-> print x + +1 + + a = f2! + -1 |> f2 + + a = f2! + - 1 |> f2 + nil 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) { } const std::string_view version() { - return "0.4.7"sv; + return "0.4.8"sv; } // 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() { expo_exp = Value >> *expo_value; unary_operator = - expr('-') >> not_(expr('>') | space_one) | + expr('-') >> not_(set(">=") | space_one) | expr('#') | - expr('~') >> not_(space_one) | + expr('~') >> not_(expr('=') | space_one) | expr("not") >> not_(AlphaNum); unary_exp = *(Space >> unary_operator) >> expo_exp; @@ -331,7 +331,7 @@ MoonParser::MoonParser() { expr(">>") | expr("//") | set("+-*/%><|&~"); - exp_op_value = White >> BinaryOperator >> *SpaceBreak >> backcall_exp; + exp_op_value = (White >> not_(unary_operator) | Space) >> BinaryOperator >> *SpaceBreak >> backcall_exp; Exp = Seperator >> backcall_exp >> *exp_op_value; ChainValue = Seperator >> (Chain | Callable) >> -existential_op >> -InvokeArgs; -- cgit v1.2.3-55-g6feb