From 6c525e381d3d1af040c3f2ee85ffbc5764c828f0 Mon Sep 17 00:00:00 2001 From: Simon Jakobi Date: Mon, 4 Nov 2019 23:24:14 +0100 Subject: [PATCH] Don't forget the other applications of commitSpaces No tests though! --- .../src/Data/Text/Prettyprint/Doc/Internal.hs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/prettyprinter/src/Data/Text/Prettyprint/Doc/Internal.hs b/prettyprinter/src/Data/Text/Prettyprint/Doc/Internal.hs index 32a53a0f..2f33847d 100755 --- a/prettyprinter/src/Data/Text/Prettyprint/Doc/Internal.hs +++ b/prettyprinter/src/Data/Text/Prettyprint/Doc/Internal.hs @@ -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 @@ -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 ->