fix: do not scan heredoc ends when it succeeds non-ws text

pull/559/head
Amaan Qureshi 2023-08-12 11:56:33 +07:00
parent 9269a4e124
commit a3935656b6
No known key found for this signature in database
GPG Key ID: E67890ADC4227273
1 changed files with 15 additions and 8 deletions

9
src/scanner.c vendored

@ -182,7 +182,7 @@ static bool scan_heredoc_content(Scanner *scanner, TSLexer *lexer,
for (;;) {
switch (lexer->lookahead) {
case '\0': {
if (did_advance) {
if (lexer->eof(lexer) && did_advance) {
scanner->heredoc_is_raw = false;
scanner->started_heredoc = false;
scanner->heredoc_allows_indent = false;
@ -234,6 +234,12 @@ static bool scan_heredoc_content(Scanner *scanner, TSLexer *lexer,
}
default: {
if (lexer->get_column(lexer) == 0) {
// an alternative is to check the starting column of the
// heredoc body and track that statefully
while (iswspace(lexer->lookahead)) {
skip(lexer);
}
if (scan_heredoc_end_identifier(scanner, lexer)) {
scanner->heredoc_is_raw = false;
scanner->started_heredoc = false;
@ -242,6 +248,7 @@ static bool scan_heredoc_content(Scanner *scanner, TSLexer *lexer,
lexer->result_symbol = end_type;
return true;
}
}
did_advance = true;
advance(lexer);
break;