Add back EOF handling

pull/357/head
Taylor Fausak 2021-11-06 15:22:13 +00:00 committed by GitHub
parent 8290109e7f
commit 85359163cc
1 changed files with 9 additions and 4 deletions

View File

@ -398,7 +398,7 @@ parsePrintModuleTests conf filename input = do
else lift else lift
$ pPrintModuleAndCheck moduleConf perItemConf anns parsedModule $ pPrintModuleAndCheck moduleConf perItemConf anns parsedModule
if null errs if null errs
then pure $ TextL.toStrict ltext then pure $ TextL.toStrict $ ltext
else else
let let
errStrs = errs <&> \case errStrs = errs <&> \case
@ -542,10 +542,15 @@ ppPreamble lmod@(L loc m@(HsModule _ _ _ _ _ _ _)) = do
modAnnsDp = ExactPrint.annsDP mAnn modAnnsDp = ExactPrint.annsDP mAnn
isWhere (ExactPrint.G AnnWhere) = True isWhere (ExactPrint.G AnnWhere) = True
isWhere _ = False isWhere _ = False
isEof (ExactPrint.AnnEofPos) = True
isEof _ = False
whereInd = List.findIndex (isWhere . fst) modAnnsDp whereInd = List.findIndex (isWhere . fst) modAnnsDp
(pre, post') = case whereInd of eofInd = List.findIndex (isEof . fst) modAnnsDp
Nothing -> ([], modAnnsDp) (pre, post') = case (whereInd, eofInd) of
Just i -> List.splitAt (i + 1) modAnnsDp (Nothing, Nothing) -> ([], modAnnsDp)
(Just i , Nothing) -> List.splitAt (i + 1) modAnnsDp
(Nothing, Just _i) -> ([], modAnnsDp)
(Just i , Just j ) -> List.splitAt (min (i + 1) j) modAnnsDp
mAnn' = mAnn { ExactPrint.annsDP = pre } mAnn' = mAnn { ExactPrint.annsDP = pre }
filteredAnns'' = filteredAnns'' =
Map.insert (ExactPrint.mkAnnKey lmod) mAnn' filteredAnns Map.insert (ExactPrint.mkAnnKey lmod) mAnn' filteredAnns