From 81928ea59715508d6d2b931bbed82f205fa9ac7d Mon Sep 17 00:00:00 2001
From: Lennart Spitzner <hexagoxel@hexagoxel.de>
Date: Wed, 14 Feb 2018 01:14:24 +0100
Subject: [PATCH] Switch to ghc-exactprint-0.5.6.0, Remove code duplication

---
 brittany.cabal                                |  2 +-
 .../Brittany/Internal/ExactPrintUtils.hs      | 39 +------------------
 2 files changed, 2 insertions(+), 39 deletions(-)

diff --git a/brittany.cabal b/brittany.cabal
index ae71fde..d0059f1 100644
--- a/brittany.cabal
+++ b/brittany.cabal
@@ -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
diff --git a/src/Language/Haskell/Brittany/Internal/ExactPrintUtils.hs b/src/Language/Haskell/Brittany/Internal/ExactPrintUtils.hs
index 7494d9e..749804c 100644
--- a/src/Language/Haskell/Brittany/Internal/ExactPrintUtils.hs
+++ b/src/Language/Haskell/Brittany/Internal/ExactPrintUtils.hs
@@ -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