@@ -907,7 +907,9 @@ extension Parser {
907907 at: openDelimiter != nil ? . leadingRaw : . leading,
908908 text: text
909909 ) ?? RawTokenSyntax ( missing: . stringQuote, arena: arena)
910- text = text. dropFirst ( openQuote. tokenText. count)
910+ if !openQuote. isMissing {
911+ text = text. dropFirst ( openQuote. tokenText. count)
912+ }
911913
912914 /// Parse segments.
913915 let ( segments, closeStart) = self . parseStringLiteralSegments (
@@ -917,16 +919,37 @@ extension Parser {
917919 /// Parse close quote.
918920 let closeQuote = self . parseStringLiteralQuote (
919921 at: openDelimiter != nil ? . trailingRaw : . trailing,
920- text: text [ closeStart ... ]
922+ text: text
921923 ) ?? 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+ }
924927 /// 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+ } ( )
926949 assert ( ( openDelimiter == nil ) == ( closeDelimiter == nil ) ,
927950 " 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 )
930953 }
931954
932955 assert ( text. isEmpty,
@@ -1060,7 +1083,10 @@ extension Parser {
10601083 // position == .leadingRaw implies that we saw a `#` before the quote.
10611084 // A multiline string literal must always start its contents on a new line.
10621085 // 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+ {
10641090 quoteCount = 1
10651091 index = text. index ( text. startIndex, offsetBy: quoteCount)
10661092 }
0 commit comments