Skip to content

Commit faab00d

Browse files
committed
Fix edge case with line continuation splitting escaped quote
1 parent 2b6adc1 commit faab00d

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

src/scanner.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -361,9 +361,11 @@ static bool scan_string_literal(TSLexer *lexer) {
361361
// both of them
362362
if (lexer->lookahead == opening_quote) {
363363
advance(lexer);
364-
// It was just one quote, so we've successfully reached the
365-
// end of the literal
366-
if (lexer->lookahead != opening_quote) {
364+
// It was just one quote, so we've successfully reached
365+
// the end of the literal. We also need to check that an
366+
// escaped quote isn't split in half by a line
367+
// continuation -- people do this!
368+
if (skip_literal_continuation_sequence(lexer) && lexer->lookahead != opening_quote) {
367369
return true;
368370
}
369371
}

test/corpus/line_continuations.txt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,10 @@ program test
200200
print*, "12&bar"
201201
print*, "&
202202
&hello"
203+
print*, "this is "&
204+
&"one string"
205+
print*, "this is "&
206+
& // "two strings"
203207
end program
204208

205209
--------------------------------------------------------------------------------
@@ -216,6 +220,16 @@ end program
216220
(format_identifier)
217221
(output_item_list
218222
(string_literal)))
223+
(print_statement
224+
(format_identifier)
225+
(output_item_list
226+
(string_literal)))
227+
(print_statement
228+
(format_identifier)
229+
(output_item_list
230+
(concatenation_expression
231+
(string_literal)
232+
(string_literal))))
219233
(end_program_statement)))
220234

221235
================================================================================

0 commit comments

Comments
 (0)