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

23
src/scanner.c vendored

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