Switch to ghc-exactprint-0.5.6.0, Remove code duplication

pull/121/head
Lennart Spitzner 2018-02-14 01:14:24 +01:00
parent 55b1c71bf3
commit 81928ea597
2 changed files with 2 additions and 39 deletions

View File

@ -82,7 +82,7 @@ library {
{ base >=4.9 && <4.11
, ghc >=8.0.1 && <8.3
, ghc-paths >=0.1.0.9 && <0.2
, ghc-exactprint >=0.5.3.0 && <0.5.6
, ghc-exactprint >=0.5.6.0 && <0.5.7
, transformers >=0.5.2.0 && <0.6
, containers >=0.5.7.1 && <0.6
, mtl >=2.2.1 && <2.3

View File

@ -113,48 +113,11 @@ parseModuleFromString args fp dynCheck str =
$ "when parsing ghc flags: encountered warnings: "
++ show (warnings <&> \(L _ s) -> s)
dynCheckRes <- ExceptT.ExceptT $ liftIO $ dynCheck dflags1
let res = parseModulePure dflags1 fp str
let res = ExactPrint.parseModuleFromStringInternal dflags1 fp str
case res of
Left (span, err) -> ExceptT.throwE $ show span ++ ": " ++ err
Right (a , m ) -> pure (a, m, dynCheckRes)
-----------
-- this function should move to ghc-exactprint. btw, we can deprecate/remove
-- the `parseModuleFromString` function that I added initially to
-- ghc-exactprint.
parseModulePure
:: GHC.DynFlags
-> System.IO.FilePath
-> String
-> Either (SrcSpan, String) (ExactPrint.Anns, GHC.ParsedSource)
parseModulePure dflags fileName str =
let (str1, lp) = ExactPrint.stripLinePragmas str
res = case runParser GHC.parseModule dflags fileName str1 of
GHC.PFailed ss m -> Left (ss, GHC.showSDoc dflags m)
GHC.POk x pmod -> Right $ (mkApiAnns x, lp, dflags, pmod)
in ExactPrint.postParseTransform res ExactPrint.normalLayout
-- copied from exactprint until exactprint exposes a proper interface.
runParser
:: GHC.P a
-> GHC.DynFlags
-> System.IO.FilePath
-> String
-> GHC.ParseResult a
runParser parser flags filename str = GHC.unP parser parseState
where
location = GHC.mkRealSrcLoc (GHC.mkFastString filename) 1 1
buffer = GHC.stringToStringBuffer str
parseState = GHC.mkPState flags buffer location
mkApiAnns :: GHC.PState -> GHC.ApiAnns
mkApiAnns pstate =
( Map.fromListWith (++) . GHC.annotations $ pstate
, Map.fromList
((GHC.noSrcSpan, GHC.comment_q pstate) : GHC.annotations_comments pstate)
)
-----------
commentAnnFixTransformGlob :: SYB.Data ast => ast -> ExactPrint.Transform ()
commentAnnFixTransformGlob ast = do