Skip to content

Commit

Permalink
Don't forget the other applications of commitSpaces
Browse files Browse the repository at this point in the history
No tests though!
  • Loading branch information
sjakobi authored and quchen committed Nov 5, 2019
1 parent b825fbf commit 6c525e3
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions prettyprinter/src/Data/Text/Prettyprint/Doc/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1465,11 +1465,13 @@ removeTrailingWhitespace = go (RecordedWhitespace [] 0)
-> Int -- Withheld spaces
-> SimpleDocStream ann
-> SimpleDocStream ann
commitSpaces [] 0 = id
commitSpaces [] 1 = SChar ' '
commitSpaces [] n = SText n (T.replicate n " ")
commitSpaces [i] n = SLine i . commitSpaces [] n
commitSpaces (_:is) n = SLine 0 . commitSpaces is n
commitSpaces is0 n0 = commitSpaces' (reverse is0) n0
where
commitSpaces' [] 0 = id
commitSpaces' [] 1 = SChar ' '
commitSpaces' [] n = SText n (T.replicate n " ")
commitSpaces' [i] n = SLine i . commitSpaces' [] n
commitSpaces' (_:is) n = SLine 0 . commitSpaces' is n

go :: WhitespaceStrippingState -> SimpleDocStream ann -> SimpleDocStream ann
-- We do not strip whitespace inside annotated documents, since it might
Expand All @@ -1494,7 +1496,7 @@ removeTrailingWhitespace = go (RecordedWhitespace [] 0)
SChar c rest
| c == ' ' -> go (RecordedWhitespace withheldLines (withheldSpaces+1)) rest
| otherwise -> commitSpaces
(reverse withheldLines)
withheldLines
withheldSpaces
(SChar c (go (RecordedWhitespace [] 0) rest))
SText textLength text rest ->
Expand Down

0 comments on commit 6c525e3

Please sign in to comment.