Skip to content

Commit 1f140c7

Browse files
thelissimusmrkkrp
authored andcommitted
Fix rendering of consecutive blank lines in multiline strings
1 parent 208c6e2 commit 1f140c7

6 files changed

Lines changed: 41 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
* Correctly format string literals containing the `\^\` escape sequence. [Issue
1616
1165](https://github.com/tweag/ormolu/issues/1165).
1717

18+
* Correctly preserve consecutive blank lines in multiline strings. [Issue
19+
1194](https://github.com/tweag/ormolu/issues/1194).
20+
1821
## Ormolu 0.8.0.2
1922

2023
* Fixed a performance regression introduced in 0.8.0.0. [Issue
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{-# LANGUAGE MultilineStrings #-}
2+
3+
multilineBlank =
4+
"""
5+
1
6+
7+
8+
9+
10+
6
11+
"""
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{-# LANGUAGE MultilineStrings #-}
2+
3+
multilineBlank =
4+
"""
5+
1
6+
7+
8+
9+
10+
6
11+
"""

src/Ormolu/Printer/Combinators.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ module Ormolu.Printer.Combinators
2121
atom,
2222
space,
2323
newline,
24+
newlineLiteral,
2425
inci,
2526
inciIf,
2627
askSourceType,

src/Ormolu/Printer/Internal.hs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ module Ormolu.Printer.Internal
1717
atom,
1818
space,
1919
newline,
20+
newlineLiteral,
2021
askSourceType,
2122
askModuleFixityMap,
2223
askDebug,
@@ -386,6 +387,19 @@ newlineRaw = R . modify $ \sc ->
386387
_ -> AfterNewline
387388
}
388389

390+
-- | Insert a newline literal without modifying the internal state of the
391+
-- parser. This is to be used exceptionally, e.g. for printing multiline
392+
-- string literals.
393+
newlineLiteral :: R ()
394+
newlineLiteral = R . modify $ \sc ->
395+
sc
396+
{ scBuilder = scBuilder sc <> "\n",
397+
scColumn = 0,
398+
scIndent = 0,
399+
scThisLineSpans = [],
400+
scRequestedDelimiter = AfterNewline
401+
}
402+
389403
-- | Return the source type.
390404
askSourceType :: R SourceType
391405
askSourceType = R (asks rcSourceType)

src/Ormolu/Printer/Meat/Declaration/StringLiteral.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ p_stringLit src = case parseStringLiteral $ T.pack $ unpackFS src of
4040
LastPos -> txt "\\" *> txt s
4141
vlayout singleLine multiLine
4242
MultilineStringLiteral ->
43-
sep breakpoint' txt segments
43+
sep newlineLiteral txt segments
4444
txt endMarker
4545

4646
-- | The start/end marker of the literal, whether it is a regular or a multiline

0 commit comments

Comments
 (0)