Skip to content

Commit

Permalink
improve semi-colon handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Nsidorenco committed Sep 21, 2024
1 parent ead20e7 commit b243ecf
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
10 changes: 8 additions & 2 deletions common/scanner.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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' &&
Expand Down Expand Up @@ -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;
Expand Down
12 changes: 12 additions & 0 deletions test/corpus/expr.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
--------------------------------------------------------------------------------

0 comments on commit b243ecf

Please sign in to comment.