aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLi Jin <dragon-fly@qq.com>2023-07-17 12:06:04 +0800
committerLi Jin <dragon-fly@qq.com>2023-07-17 12:06:04 +0800
commit2faf55a8217690988bc2cab7cc65541dc2215dc1 (patch)
treeb7f772d3384e85f3cdb2ec12983e1d7b62987ce7
parent1d2423bff4ecc4396d65c387982d6667b33bd796 (diff)
downloadyuescript-2faf55a8217690988bc2cab7cc65541dc2215dc1.tar.gz
yuescript-2faf55a8217690988bc2cab7cc65541dc2215dc1.tar.bz2
yuescript-2faf55a8217690988bc2cab7cc65541dc2215dc1.zip
raise error when writing a confusing expression in in-expression.
-rw-r--r--src/yuescript/yue_compiler.cpp2
-rw-r--r--src/yuescript/yue_parser.cpp7
-rw-r--r--src/yuescript/yue_parser.h1
3 files changed, 8 insertions, 2 deletions
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<std::string> Metamethods = {
72 "close"s // Lua 5.4 72 "close"s // Lua 5.4
73}; 73};
74 74
75const std::string_view version = "0.17.6"sv; 75const std::string_view version = "0.17.7"sv;
76const std::string_view extension = "yue"sv; 76const std::string_view extension = "yue"sv;
77 77
78class CompileError : public std::logic_error { 78class 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() {
103 return false; 103 return false;
104 }); 104 });
105 105
106 confusing_unary_not_error = pl::user(true_(), [](const item_t& item) {
107 throw ParserError("deprecated unary operator not"sv, item.begin);
108 return false;
109 });
110
106 #define ensure(patt, finally) ((patt) >> (finally) | (finally) >> cut) 111 #define ensure(patt, finally) ((patt) >> (finally) | (finally) >> cut)
107 112
108 #define key(str) (expr(str) >> not_alpha_num) 113 #define key(str) (expr(str) >> not_alpha_num)
@@ -464,7 +469,7 @@ YueParser::YueParser() {
464 NotIn = true_(); 469 NotIn = true_();
465 InRange = ('(' >> InRangeOpen | '[' >> InRangeClose) >> space >> Exp >> space >> ',' >> space >> Exp >> space >> (')' >> InRangeOpen | ']' >> InRangeClose); 470 InRange = ('(' >> InRangeOpen | '[' >> InRangeClose) >> space >> Exp >> space >> ',' >> space >> Exp >> space >> (')' >> InRangeOpen | ']' >> InRangeClose);
466 InDiscrete = '{' >> Seperator >> space >> exp_not_tab >> *(space >> ',' >> space >> exp_not_tab) >> space >> '}'; 471 InDiscrete = '{' >> Seperator >> space >> exp_not_tab >> *(space >> ',' >> space >> exp_not_tab) >> space >> '}';
467 In = -(key("not") >> NotIn >> space) >> key("in") >> space >> (InRange | InDiscrete | Exp); 472 In = -(key("not") >> NotIn >> space) >> key("in") >> space >> (InRange | InDiscrete | key("not") >> confusing_unary_not_error | Exp);
468 473
469 UnaryOperator = 474 UnaryOperator =
470 '-' >> not_(set(">=") | space_one) | 475 '-' >> 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:
138 NONE_AST_RULE(brackets_expression_error); 138 NONE_AST_RULE(brackets_expression_error);
139 NONE_AST_RULE(export_expression_error); 139 NONE_AST_RULE(export_expression_error);
140 NONE_AST_RULE(invalid_interpolation_error); 140 NONE_AST_RULE(invalid_interpolation_error);
141 NONE_AST_RULE(confusing_unary_not_error);
141 142
142 NONE_AST_RULE(inc_exp_level); 143 NONE_AST_RULE(inc_exp_level);
143 NONE_AST_RULE(dec_exp_level); 144 NONE_AST_RULE(dec_exp_level);