From b243ecf2924c06b034e4abfb3f8c867e32fa265e Mon Sep 17 00:00:00 2001 From: nsidorenco Date: Sat, 21 Sep 2024 12:45:46 +0200 Subject: [PATCH] improve semi-colon handling --- common/scanner.h | 10 ++++++++-- test/corpus/expr.txt | 12 ++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/common/scanner.h b/common/scanner.h index 4fd1364..99c499f 100644 --- a/common/scanner.h +++ b/common/scanner.h @@ -179,6 +179,7 @@ static bool scan(Scanner *scanner, TSLexer *lexer, const bool *valid_symbols) { lexer->mark_end(lexer); bool found_end_of_line = false; + bool found_end_of_line_semi_colon = false; bool found_start_of_infix_op = false; bool found_bracket_end = false; bool found_preprocessor_end = false; @@ -399,9 +400,9 @@ static bool scan(Scanner *scanner, TSLexer *lexer, const bool *valid_symbols) { while (lexer->lookahead == ' ' || lexer->lookahead == '\n') { advance(lexer); } + found_end_of_line = true; + found_end_of_line_semi_colon = true; lexer->mark_end(lexer); - lexer->result_symbol = NEWLINE; - return true; } if (lexer->lookahead == 't' && @@ -601,6 +602,11 @@ static bool scan(Scanner *scanner, TSLexer *lexer, const bool *valid_symbols) { } } + if (valid_symbols[NEWLINE] && found_end_of_line_semi_colon) { + lexer->result_symbol = NEWLINE; + return true; + } + if (valid_symbols[INDENT] && !found_bracket_end && !found_preprocessor_end) { array_push(&scanner->indents, indent_length); lexer->result_symbol = INDENT; diff --git a/test/corpus/expr.txt b/test/corpus/expr.txt index e050558..c46cc3a 100644 --- a/test/corpus/expr.txt +++ b/test/corpus/expr.txt @@ -3743,3 +3743,15 @@ do (identifier)))) (const (int)))))))) + +================================================================================ +if-then-else with semi-colon eol +================================================================================ + +do + let _name = x.F("ViewModel", ""); + let _type = T.G(_name); + if _type <> null + then A.C(_type) :?> I; + else T( Text = "Not Found: " + _name ) :> I +--------------------------------------------------------------------------------