@@ -478,6 +478,19 @@ function lex_string_chunk(l)
478
478
# Start interpolation
479
479
readchar (l)
480
480
return emit (l, Tokens. EX_OR)
481
+ elseif ! state. raw && pc == ' \\ ' && (pc2 = dpeekchar (l)[2 ];
482
+ pc2 == ' \r ' || pc2 == ' \n ' )
483
+ # Process escaped newline as whitespace
484
+ readchar (l)
485
+ readon (l)
486
+ readchar (l)
487
+ if pc2 == ' \r ' && peekchar (l) == ' \n '
488
+ readchar (l)
489
+ end
490
+ while (pc = peekchar (l); pc == ' ' || pc == ' \t ' )
491
+ readchar (l)
492
+ end
493
+ return emit (l, Tokens. WHITESPACE)
481
494
elseif pc == state. delim && string_terminates (l, state. delim, state. triplestr)
482
495
# Terminate string
483
496
pop! (l. string_states)
@@ -493,14 +506,55 @@ function lex_string_chunk(l)
493
506
readon (l)
494
507
# Read a chunk of string characters
495
508
if state. raw
496
- read_raw_string (l, state. delim, state. triplestr)
509
+ # Raw strings treat all characters as literals with the exception that
510
+ # the closing quotes can be escaped with an odd number of \ characters.
511
+ while true
512
+ pc = peekchar (l)
513
+ if string_terminates (l, state. delim, state. triplestr) || eof (pc)
514
+ break
515
+ elseif state. triplestr && (pc == ' \n ' || pc == ' \r ' )
516
+ # triple quoted newline splitting
517
+ readchar (l)
518
+ if pc == ' \r ' && peekchar (l) == ' \n '
519
+ readchar (l)
520
+ end
521
+ break
522
+ end
523
+ c = readchar (l)
524
+ if c == ' \\ '
525
+ n = 1
526
+ while true
527
+ readchar (l)
528
+ n += 1
529
+ if peekchar (l) != ' \\ '
530
+ break
531
+ end
532
+ end
533
+ if peekchar (l) == state. delim && ! iseven (n)
534
+ readchar (l)
535
+ end
536
+ end
537
+ end
497
538
else
498
539
while true
499
540
pc = peekchar (l)
500
541
if pc == ' $' || eof (pc)
501
542
break
543
+ elseif state. triplestr && (pc == ' \n ' || pc == ' \r ' )
544
+ # triple quoted newline splitting
545
+ readchar (l)
546
+ if pc == ' \r ' && peekchar (l) == ' \n '
547
+ readchar (l)
548
+ end
549
+ break
502
550
elseif pc == state. delim && string_terminates (l, state. delim, state. triplestr)
503
551
break
552
+ elseif pc == ' \\ '
553
+ # Escaped newline
554
+ pc2 = dpeekchar (l)[2 ]
555
+ if pc2 == ' \r ' || pc2 == ' \n '
556
+ break
557
+ end
504
558
end
505
559
c = readchar (l)
506
560
if c == ' \\ '
@@ -928,44 +982,6 @@ function string_terminates(l, delim::Char, triplestr::Bool)
928
982
end
929
983
end
930
984
931
- function terminate_string (l, delim:: Char , triplestr:: Bool )
932
- # @assert string_terminates(l, delim, triplestr)
933
- readchar (l)
934
- if triplestr
935
- readchar (l)
936
- readchar (l)
937
- return delim == ' "' ? Tokens. TRIPLE_DQUOTE : Tokens. TRIPLE_BACKTICK
938
- else
939
- return delim == ' "' ? Tokens. DQUOTE : Tokens. BACKTICK
940
- end
941
- end
942
-
943
- # Read a raw string for use with custom string macros
944
- #
945
- # Raw strings treat all characters as literals with the exception that the
946
- # closing quotes can be escaped with an odd number of \ characters.
947
- function read_raw_string (l:: Lexer , delim:: Char , triplestr:: Bool )
948
- while true
949
- if string_terminates (l, delim, triplestr) || eof (peekchar (l))
950
- return
951
- end
952
- c = readchar (l)
953
- if c == ' \\ '
954
- n = 1
955
- while true
956
- readchar (l)
957
- n += 1
958
- if peekchar (l) != ' \\ '
959
- break
960
- end
961
- end
962
- if peekchar (l) == delim && ! iseven (n)
963
- readchar (l)
964
- end
965
- end
966
- end
967
- end
968
-
969
985
# Parse a token starting with a forward slash.
970
986
# A '/' has been consumed
971
987
function lex_forwardslash (l:: Lexer )
0 commit comments