Fix comment/eof space handling (fixes #22)

pull/35/head
Lennart Spitzner 2017-04-15 14:50:55 +02:00
parent 505ad99f35
commit cbeab39b2d
1 changed files with 12 additions and 8 deletions

View File

@ -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
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
_ -> acc + x
cmX = foldl' folder 0 finalComments
in ppmMoveToExactLoc $ ExactPrint.Types.DP (eofX - cmX, eofY)
-> ( 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 ()