From 2faf55a8217690988bc2cab7cc65541dc2215dc1 Mon Sep 17 00:00:00 2001 From: Li Jin Date: Mon, 17 Jul 2023 12:06:04 +0800 Subject: raise error when writing a confusing expression in in-expression. --- src/yuescript/yue_compiler.cpp | 2 +- src/yuescript/yue_parser.cpp | 7 ++++++- src/yuescript/yue_parser.h | 1 + 3 files changed, 8 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/yuescript/yue_compiler.cpp b/src/yuescript/yue_compiler.cpp index c6cc4ba..bb715d2 100644 --- a/src/yuescript/yue_compiler.cpp +++ b/src/yuescript/yue_compiler.cpp @@ -72,7 +72,7 @@ static std::unordered_set Metamethods = { "close"s // Lua 5.4 }; -const std::string_view version = "0.17.6"sv; +const std::string_view version = "0.17.7"sv; const std::string_view extension = "yue"sv; class CompileError : public std::logic_error { diff --git a/src/yuescript/yue_parser.cpp b/src/yuescript/yue_parser.cpp index 66ef373..f9dc33a 100644 --- a/src/yuescript/yue_parser.cpp +++ b/src/yuescript/yue_parser.cpp @@ -103,6 +103,11 @@ YueParser::YueParser() { return false; }); + confusing_unary_not_error = pl::user(true_(), [](const item_t& item) { + throw ParserError("deprecated unary operator not"sv, item.begin); + return false; + }); + #define ensure(patt, finally) ((patt) >> (finally) | (finally) >> cut) #define key(str) (expr(str) >> not_alpha_num) @@ -464,7 +469,7 @@ YueParser::YueParser() { NotIn = true_(); InRange = ('(' >> InRangeOpen | '[' >> InRangeClose) >> space >> Exp >> space >> ',' >> space >> Exp >> space >> (')' >> InRangeOpen | ']' >> InRangeClose); InDiscrete = '{' >> Seperator >> space >> exp_not_tab >> *(space >> ',' >> space >> exp_not_tab) >> space >> '}'; - In = -(key("not") >> NotIn >> space) >> key("in") >> space >> (InRange | InDiscrete | Exp); + In = -(key("not") >> NotIn >> space) >> key("in") >> space >> (InRange | InDiscrete | key("not") >> confusing_unary_not_error | Exp); UnaryOperator = '-' >> not_(set(">=") | space_one) | diff --git a/src/yuescript/yue_parser.h b/src/yuescript/yue_parser.h index ac6524d..dd5e253 100644 --- a/src/yuescript/yue_parser.h +++ b/src/yuescript/yue_parser.h @@ -138,6 +138,7 @@ private: NONE_AST_RULE(brackets_expression_error); NONE_AST_RULE(export_expression_error); NONE_AST_RULE(invalid_interpolation_error); + NONE_AST_RULE(confusing_unary_not_error); NONE_AST_RULE(inc_exp_level); NONE_AST_RULE(dec_exp_level); -- cgit v1.2.3-55-g6feb