Skip to content

Commit 0cbfc85

Browse files
committed
Fix string literals immediately followed by line continuation
Previously: ```f90 print*, 'this looks like implicit '& 'concatenation but isn''t' print*, "this explicit concatenation "& // "is intended" ``` would get parsed as ``` 8:2 - 9:33 print_statement 8:2 - 8:7 "print" 8:7 - 8:8 format_identifier 8:7 - 8:8 "*" 8:8 - 8:9 "," 9:7 - 9:33 output_item_list 9:7 - 9:33 string_literal `'concatenation but isn''t'` 10:2 - 11:23 print_statement 10:2 - 10:7 "print" 10:7 - 10:8 format_identifier 10:7 - 10:8 "*" 10:8 - 10:9 "," 11:7 - 11:23 output_item_list 11:7 - 11:23 concatenation_expression 11:7 - 11:7 left: string_literal 11:7 - 11:9 "//" 11:10 - 11:23 right: string_literal `"is intended"` ``` Note first half of literal is missing! Now gets parsed as: ``` 8:2 - 9:33 print_statement 8:2 - 8:7 "print" 8:7 - 8:8 format_identifier 8:7 - 8:8 "*" 8:8 - 8:9 "," 8:10 - 9:33 output_item_list 8:10 - 9:33 string_literal 8:10 - 8:39 `'this looks like implicit '&\n` 9:10 - 9:33 ` 'concatenation but isn''t'` 10:2 - 11:23 print_statement 10:2 - 10:7 "print" 10:7 - 10:8 format_identifier 10:7 - 10:8 "*" 10:8 - 10:9 "," 10:10 - 11:23 output_item_list 10:10 - 11:23 concatenation_expression 10:10 - 10:40 left: string_literal `"this explicit concatenation "` 10:40 - 10:41 "&" 11:7 - 11:7 "&" 11:7 - 11:9 "//" 11:10 - 11:23 right: string_literal `"is intended"` ``` Full literal text is now included. No tests because this is in the CST, and that's not captured in the tests
1 parent 52a59d5 commit 0cbfc85

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/scanner.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,13 +153,13 @@ static bool skip_literal_continuation_sequence(TSLexer *lexer) {
153153
return true;
154154
}
155155

156-
skip(lexer);
156+
advance(lexer);
157157
while (iswspace(lexer->lookahead)) {
158-
skip(lexer);
158+
advance(lexer);
159159
}
160-
// second '&' required to continue the literal
160+
// second '&' technically required to continue the literal
161161
if (lexer->lookahead == '&') {
162-
skip(lexer);
162+
advance(lexer);
163163
return true;
164164
}
165165
return false;
@@ -365,6 +365,7 @@ static bool scan_string_literal(TSLexer *lexer) {
365365
// the end of the literal. We also need to check that an
366366
// escaped quote isn't split in half by a line
367367
// continuation -- people do this!
368+
lexer->mark_end(lexer);
368369
skip_literal_continuation_sequence(lexer);
369370
if (lexer->lookahead != opening_quote) {
370371
return true;

0 commit comments

Comments
 (0)