From bd10e55e72cfd588d3ed1ef6330bc138a3fe8eff Mon Sep 17 00:00:00 2001 From: Li Jin Date: Tue, 8 Nov 2022 15:15:37 +0800 Subject: added indentation error messages. --- spec/inputs/try-catch.yue | 4 ++-- src/yuescript/yue_compiler.cpp | 2 +- src/yuescript/yue_parser.cpp | 9 +++++++-- src/yuescript/yue_parser.h | 1 + 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/spec/inputs/try-catch.yue b/spec/inputs/try-catch.yue index f5cb97e..7287c33 100644 --- a/spec/inputs/try-catch.yue +++ b/spec/inputs/try-catch.yue @@ -34,8 +34,8 @@ catch err if try func 1 catch err - print err - print "OK" + print err + print "OK" do if success, result = try func "abc", 123 diff --git a/src/yuescript/yue_compiler.cpp b/src/yuescript/yue_compiler.cpp index d0f2dbb..45a9bf6 100644 --- a/src/yuescript/yue_compiler.cpp +++ b/src/yuescript/yue_compiler.cpp @@ -59,7 +59,7 @@ namespace yue { typedef std::list str_list; -const std::string_view version = "0.15.9"sv; +const std::string_view version = "0.15.10"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 e4de0b5..e755fb2 100644 --- a/src/yuescript/yue_parser.cpp +++ b/src/yuescript/yue_parser.cpp @@ -679,10 +679,15 @@ YueParser::YueParser() { advance >> ensure(MultiLineComment >> Space | Comment, PopIndent) | plain_space) >> and_(Break); + indentation_error = pl::user(not_(PipeOperator), [](const item_t& item) { + throw ParserError("unexpected indent", *item.begin, *item.end); + return false; + }); + Line = CheckIndent >> Statement | - Advance >> ensure(Space >> and_(PipeOperator) >> Statement, PopIndent) | - empty_line_break; + empty_line_break | + Advance >> ensure(Space >> (indentation_error | Statement), PopIndent); Block = Seperator >> Line >> *(+Break >> Line); Shebang = expr("#!") >> *(not_(Stop) >> Any); diff --git a/src/yuescript/yue_parser.h b/src/yuescript/yue_parser.h index 9e2a621..74281fb 100644 --- a/src/yuescript/yue_parser.h +++ b/src/yuescript/yue_parser.h @@ -117,6 +117,7 @@ private: rule empty_block_error; rule leading_spaces_error; + rule indentation_error; rule num_char; rule num_char_hex; -- cgit v1.2.3-55-g6feb