@@ -28,7 +28,7 @@ p_stringLit src = case parseStringLiteral $ T.pack $ unpackFS src of
28
28
case stringLiteralKind of
29
29
RegularStringLiteral -> do
30
30
let singleLine =
31
- txt $ T. concat segments
31
+ txt $ intercalateMinimalStringGaps segments
32
32
multiLine =
33
33
sep breakpoint f (attachRelativePos segments)
34
34
where
@@ -105,9 +105,9 @@ parseStringLiteral = \s -> do
105
105
splitMultilineString :: Text -> [Text ]
106
106
splitMultilineString =
107
107
splitGaps
108
- -- There is no reason to use gaps with multiline string literals, so
109
- -- we collapse them.
110
- >>> T. concat
108
+ -- There is no reason to use gaps with multiline string literals just to
109
+ -- emulate multi-line strings, so we replace them with "\\ \\" .
110
+ >>> intercalateMinimalStringGaps
111
111
>>> splitNewlines
112
112
>>> fmap expandLeadingTabs
113
113
>>> rmCommonWhitespacePrefixAndBlank
@@ -150,3 +150,12 @@ parseStringLiteral = \s -> do
150
150
| otherwise = (Just $ Min leadingSpace, T. drop commonWs l)
151
151
where
152
152
leadingSpace = T. length $ T. takeWhile is_space l
153
+
154
+ -- | Add minimal string gaps between string literal chunks. Such string gaps
155
+ -- /can/ be semantically meaningful (so we preserve them for simplicity); for
156
+ -- example:
157
+ --
158
+ -- >>> "\65\ \0" == "\650"
159
+ -- False
160
+ intercalateMinimalStringGaps :: [Text ] -> Text
161
+ intercalateMinimalStringGaps = T. intercalate " \\ \\ "
0 commit comments