Skip to content

Commit

Permalink
Merge pull request #137 from alanz/ghc-9.10-cleanups
Browse files Browse the repository at this point in the history
Ghc 9.10 cleanups
  • Loading branch information
alanz committed May 21, 2024
2 parents 630c4e8 + 5e7e8ab commit e867719
Show file tree
Hide file tree
Showing 5 changed files with 372 additions and 460 deletions.
38 changes: 12 additions & 26 deletions src/Language/Haskell/GHC/ExactPrint/ExactPrint.hs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ module Language.Haskell.GHC.ExactPrint.ExactPrint
, makeDeltaAst

-- * Configuration
, EPOptions(epRigidity, epAstPrint, epTokenPrint, epWhitespacePrint, epUpdateAnchors)
, EPOptions(epTokenPrint, epWhitespacePrint)
, stringOptions
, epOptions
, deltaOptions
Expand Down Expand Up @@ -79,18 +79,16 @@ import Language.Haskell.GHC.ExactPrint.Types
exactPrint :: ExactPrint ast => ast -> String
exactPrint ast = snd $ runIdentity (runEP stringOptions (markAnnotated ast))

-- | The additional option to specify the rigidity and printing
-- configuration.
-- | The additional option to specify the printing configuration.
exactPrintWithOptions :: (ExactPrint ast, Monoid b, Monad m)
=> EPOptions m b
-> ast
-> m (ast, b)
exactPrintWithOptions r ast =
runEP r (markAnnotated ast)

-- | Transform concrete annotations into relative annotations which
-- are more useful when transforming an AST. This corresponds to the
-- earlier 'relativiseApiAnns'.
-- | Transform concrete annotations into relative annotations.
-- This should be unnecessary from GHC 9.10
makeDeltaAst :: ExactPrint ast => ast -> ast
makeDeltaAst ast = fst $ runIdentity (runEP deltaOptions (markAnnotated ast))

Expand Down Expand Up @@ -131,39 +129,27 @@ defaultEPState = EPState
-- | The R part of RWS. The environment. Updated via 'local' as we
-- enter a new AST element, having a different anchor point.
data EPOptions m a = EPOptions
{
epAstPrint :: forall ast . Data ast => GHC.Located ast -> a -> m a
, epTokenPrint :: String -> m a
{ epTokenPrint :: String -> m a
, epWhitespacePrint :: String -> m a
, epRigidity :: Rigidity
, epUpdateAnchors :: Bool
}

-- | Helper to create a 'EPOptions'
epOptions ::
(forall ast . Data ast => GHC.Located ast -> a -> m a)
-> (String -> m a)
-> (String -> m a)
-> Rigidity
-> Bool
-> EPOptions m a
epOptions astPrint tokenPrint wsPrint rigidity delta = EPOptions
{
epAstPrint = astPrint
, epWhitespacePrint = wsPrint
epOptions :: (String -> m a)
-> (String -> m a)
-> EPOptions m a
epOptions tokenPrint wsPrint = EPOptions
{ epWhitespacePrint = wsPrint
, epTokenPrint = tokenPrint
, epRigidity = rigidity
, epUpdateAnchors = delta
}

-- | Options which can be used to print as a normal String.
stringOptions :: EPOptions Identity String
stringOptions = epOptions (\_ b -> return b) return return NormalLayout False
stringOptions = epOptions return return

-- | Options which can be used to simply update the AST to be in delta
-- form, without generating output
deltaOptions :: EPOptions Identity ()
deltaOptions = epOptions (\_ _ -> return ()) (\_ -> return ()) (\_ -> return ()) NormalLayout True
deltaOptions = epOptions (\_ -> return ()) (\_ -> return ())

data EPWriter a = EPWriter
{ output :: !a }
Expand Down
Loading

0 comments on commit e867719

Please sign in to comment.