From cbeab39b2df527b63aacc333bcd64cb565179fb4 Mon Sep 17 00:00:00 2001 From: Lennart Spitzner Date: Sat, 15 Apr 2017 14:50:55 +0200 Subject: [PATCH] Fix comment/eof space handling (fixes #22) --- src/Language/Haskell/Brittany.hs | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/Language/Haskell/Brittany.hs b/src/Language/Haskell/Brittany.hs index d45ef98..dc77b76 100644 --- a/src/Language/Haskell/Brittany.hs +++ b/src/Language/Haskell/Brittany.hs @@ -202,13 +202,17 @@ ppModule lmod@(L loc m@(HsModule _name _exports _imports decls _ _)) = do ppmMoveToExactLoc l mTell $ Text.Builder.fromString cmStr (ExactPrint.Types.G AnnEofPos, (ExactPrint.Types.DP (eofX, eofY))) -> - let folder acc (kw, ExactPrint.Types.DP (x, _)) = case kw of - ExactPrint.Types.AnnComment cm - | GHC.RealSrcSpan span <- ExactPrint.Types.commentIdentifier cm - -> acc + x + GHC.srcSpanEndLine span - GHC.srcSpanStartLine span - _ -> acc + x - cmX = foldl' folder 0 finalComments - in ppmMoveToExactLoc $ ExactPrint.Types.DP (eofX - cmX, eofY) + let + folder (acc, _) (kw, ExactPrint.Types.DP (x, y)) = case kw of + ExactPrint.Types.AnnComment cm + | GHC.RealSrcSpan span <- ExactPrint.Types.commentIdentifier cm + -> ( acc + x + GHC.srcSpanEndLine span - GHC.srcSpanStartLine span + , y + GHC.srcSpanEndCol span - GHC.srcSpanStartCol span + ) + _ -> (acc + x, y) + (cmX, cmY) = foldl' folder (0, 0) finalComments + in + ppmMoveToExactLoc $ ExactPrint.Types.DP (eofX - cmX, eofY - cmY) _ -> return () withTransformedAnns :: SYB.Data ast => ast -> PPM () -> PPM () @@ -224,7 +228,7 @@ withTransformedAnns ast m = do ExactPrint.runTransform anns (commentAnnFixTransformGlob ast) in annsBalanced - + ppDecl :: LHsDecl RdrName -> PPM () ppDecl d@(L loc decl) = case decl of SigD sig -> -- trace (_sigHead sig) $