From a6dc9009035113858acac32cd083983c42bc9de6 Mon Sep 17 00:00:00 2001 From: Li Jin Date: Mon, 11 Dec 2023 09:40:29 +0800 Subject: fix empty block ends with eof issue. --- spec/inputs/syntax.yue | 18 ++++++++++++++++++ spec/outputs/syntax.lua | 16 ++++++++++++++++ src/yuescript/yue_parser.cpp | 2 +- 3 files changed, 35 insertions(+), 1 deletion(-) diff --git a/spec/inputs/syntax.yue b/spec/inputs/syntax.yue index d60a145..271f43f 100644 --- a/spec/inputs/syntax.yue +++ b/spec/inputs/syntax.yue @@ -460,5 +460,23 @@ do ) f ! +do + if cond + -- + else + -- + + switch cond + when 1 + -- + when 2 + -- + else + -- + + f1 = -> -- + f2 = -> + -- + nil diff --git a/spec/outputs/syntax.lua b/spec/outputs/syntax.lua index 2afadbb..20b8469 100644 --- a/spec/outputs/syntax.lua +++ b/spec/outputs/syntax.lua @@ -412,4 +412,20 @@ do f(a, b) f() end +do + if cond then + else + end + do + local _exp_0 = cond + if 1 == _exp_0 then + elseif 2 == _exp_0 then + else + end + end + local f1 + f1 = function() end + local f2 + f2 = function() end +end return nil diff --git a/src/yuescript/yue_parser.cpp b/src/yuescript/yue_parser.cpp index 5b97a25..4b865f5 100644 --- a/src/yuescript/yue_parser.cpp +++ b/src/yuescript/yue_parser.cpp @@ -958,7 +958,7 @@ YueParser::YueParser() { check_indent >> (multi_line_comment >> space | comment) | advance >> ensure(multi_line_comment >> space | comment, pop_indent) | plain_space - ) >> and_(line_break); + ) >> and_(stop); indentation_error = pl::user(not_(pipe_operator | eof()), [](const item_t& item) { throw ParserError("unexpected indent"sv, item.begin); -- cgit v1.2.3-55-g6feb