From 3f881ba631a935b6d5ac2e4fc3fec9f08e498542 Mon Sep 17 00:00:00 2001 From: Li Jin Date: Sun, 22 Jan 2023 07:15:02 +0800 Subject: fixing issue #120 again. --- 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 6fd43d0..5443c61 100644 --- a/src/yuescript/yue_compiler.cpp +++ b/src/yuescript/yue_compiler.cpp @@ -71,7 +71,7 @@ static std::unordered_set Metamethods = { "close"s // Lua 5.4 }; -const std::string_view version = "0.15.22"sv; +const std::string_view version = "0.15.23"sv; const std::string_view extension = "yue"sv; class YueCompilerImpl { diff --git a/src/yuescript/yue_parser.cpp b/src/yuescript/yue_parser.cpp index 4532d21..2fc1333 100644 --- a/src/yuescript/yue_parser.cpp +++ b/src/yuescript/yue_parser.cpp @@ -387,7 +387,7 @@ YueParser::YueParser() { Comprehension = '[' >> not_('[') >> space >> Exp >> space >> CompInner >> space >> ']'; CompValue = ',' >> space >> Exp; - TblComprehension = '{' >> space >> Exp >> space >> -(CompValue >> space) >> CompInner >> space >> '}'; + TblComprehension = '{' >> (space >> Exp >> space >> -(CompValue >> space) >> CompInner >> space >> '}' | braces_expression_error); CompInner = Seperator >> (CompForEach | CompFor) >> *(space >> comp_clause); StarExp = '*' >> space >> Exp; @@ -736,6 +736,11 @@ YueParser::YueParser() { ConstValue = (expr("nil") | "true" | "false") >> not_alpha_num; + braces_expression_error = pl::user("{", [](const item_t& item) { + throw ParserError("invalid brace expression", *item.begin, *item.end); + return false; + }); + SimpleValue = TableLit | ConstValue | If | Switch | Try | With | ClassDecl | ForEach | For | While | Do | diff --git a/src/yuescript/yue_parser.h b/src/yuescript/yue_parser.h index da25d3d..c8fc17e 100644 --- a/src/yuescript/yue_parser.h +++ b/src/yuescript/yue_parser.h @@ -118,6 +118,7 @@ private: rule empty_block_error; rule leading_spaces_error; rule indentation_error; + rule braces_expression_error; rule num_char; rule num_char_hex; -- cgit v1.2.3-55-g6feb