@@ -907,7 +907,9 @@ extension Parser {
907
907
at: openDelimiter != nil ? . leadingRaw : . leading,
908
908
text: text
909
909
) ?? RawTokenSyntax ( missing: . stringQuote, arena: arena)
910
- text = text. dropFirst ( openQuote. tokenText. count)
910
+ if !openQuote. isMissing {
911
+ text = text. dropFirst ( openQuote. tokenText. count)
912
+ }
911
913
912
914
/// Parse segments.
913
915
let ( segments, closeStart) = self . parseStringLiteralSegments (
@@ -917,16 +919,37 @@ extension Parser {
917
919
/// Parse close quote.
918
920
let closeQuote = self . parseStringLiteralQuote (
919
921
at: openDelimiter != nil ? . trailingRaw : . trailing,
920
- text: text [ closeStart ... ]
922
+ text: text
921
923
) ?? RawTokenSyntax ( missing: openQuote. tokenKind, arena: arena)
922
- text = text. dropFirst ( closeQuote. byteLength)
923
-
924
+ if !closeQuote. isMissing {
925
+ text = text. dropFirst ( closeQuote. tokenText. count)
926
+ }
924
927
/// Parse closing raw string delimiter if exist.
925
- let closeDelimiter = self . parseStringLiteralDelimiter ( at: . trailing, text: text)
928
+ let closeDelimiter : RawTokenSyntax ? = {
929
+ if let closeDelimiter = self . parseStringLiteralDelimiter (
930
+ at: . trailing,
931
+ text: text
932
+ ) {
933
+ return closeDelimiter
934
+ }
935
+
936
+ if let openDelimiter = openDelimiter {
937
+ return RawTokenSyntax (
938
+ kind: . rawStringDelimiter,
939
+ text: openDelimiter. tokenText,
940
+ leadingTriviaPieces: [ ] ,
941
+ trailingTriviaPieces: [ ] ,
942
+ presence: . missing,
943
+ arena: arena
944
+ )
945
+ }
946
+
947
+ return nil
948
+ } ( )
926
949
assert ( ( openDelimiter == nil ) == ( closeDelimiter == nil ) ,
927
950
" existence of open/close delimiter should match " )
928
- if let closeDelimiter = closeDelimiter {
929
- text = text. dropFirst ( closeDelimiter. tokenText . count )
951
+ if let closeDelimiter = closeDelimiter, !closeDelimiter . isMissing {
952
+ text = text. dropFirst ( closeDelimiter. byteLength )
930
953
}
931
954
932
955
assert ( text. isEmpty,
@@ -1060,7 +1083,10 @@ extension Parser {
1060
1083
// position == .leadingRaw implies that we saw a `#` before the quote.
1061
1084
// A multiline string literal must always start its contents on a new line.
1062
1085
// Thus we are parsing somethign like #"""#, which is not a multiline string literal but a raw literal containing a single quote.
1063
- if position == . leadingRaw && text [ index] == UInt8 ( ascii: " # " ) {
1086
+ if position == . leadingRaw,
1087
+ index < text. endIndex,
1088
+ text [ index] == UInt8 ( ascii: " # " )
1089
+ {
1064
1090
quoteCount = 1
1065
1091
index = text. index ( text. startIndex, offsetBy: quoteCount)
1066
1092
}
0 commit comments