Monad type for updating the AST and managing the annotations at the same time. The W state is used to generate logging information if required.
Moduleghc-exactprint-1.10.0.0Haskell2010
Language.Haskell.GHC.ExactPrint.Transform
This module is currently under heavy development, and no promises are made about API stability. Use with care.
We welcome any feedback / contributions on this, as it is the main point of the library.
- 3 types
- 2 classes
- 47 values
- Packageghc-exactprint-1.10.0.0
- Exports52
- LanguageHaskell2010
- LicenceBSD-3-Clause
- SourceTransform.hs
The Transform Monad
7 declarationsMonad transformer version of Transform monad
Constructors
TransformTunTransformT :: RWST () [String] Int m a
Instances9MonadTrans, MonadReader, MonadState, Monad, Functor, MonadFail, …
MonadTrans TransformTDefined in ghc-exactprint-1.10.0.0 · Language.Haskell.GHC.ExactPrint.TransformMonad m => MonadReader () (TransformT m)Defined in ghc-exactprint-1.10.0.0 · Language.Haskell.GHC.ExactPrint.TransformMonad m => MonadState Int (TransformT m)Defined in ghc-exactprint-1.10.0.0 · Language.Haskell.GHC.ExactPrint.TransformMonad m => Monad (TransformT m)Defined in ghc-exactprint-1.10.0.0 · Language.Haskell.GHC.ExactPrint.TransformFunctor m => Functor (TransformT m)Defined in ghc-exactprint-1.10.0.0 · Language.Haskell.GHC.ExactPrint.TransformMonadFail m => MonadFail (TransformT m)Defined in ghc-exactprint-1.10.0.0 · Language.Haskell.GHC.ExactPrint.TransformMonad m => Applicative (TransformT m)Defined in ghc-exactprint-1.10.0.0 · Language.Haskell.GHC.ExactPrint.TransformMonad m => HasTransform (TransformT m)Defined in ghc-exactprint-1.10.0.0 · Language.Haskell.GHC.ExactPrint.TransformMonad m => MonadWriter [String] (TransformT m)Defined in ghc-exactprint-1.10.0.0 · Language.Haskell.GHC.ExactPrint.Transform
Change inner monad of TransformT.
Run a monad transformer stack for the TransformT monad transformer
Transform monad operations
3 declarationsLog a string to the output of the Monad
Log a representation of the given AST with annotations to the output of the Monad
If we need to add new elements to the AST, they need their own
SrcSpan for this.
This should no longer be needed, we use an EpaDelta location instead.
Managing declarations, in Transform monad
Instances1HasTransform
Monad m => HasTransform (TransformT m)Defined in ghc-exactprint-1.10.0.0 · Language.Haskell.GHC.ExactPrint.Transform
Provide a means to get and process the immediate child declarations of a given AST element.
Methods
hsDecls :: t -> [LHsDecl GhcPs]replaceDecls :: t -> [LHsDecl GhcPs] -> tReplace the directly enclosed decl list by the given decl list. As parto of replacing it will update list order annotations, and rebalance comments and other layout changes as needed.
For example, a call on replaceDecls for a wrapped FunBind having no where clause will convert
-- |This is a function foo = x -- comment1in to
-- |This is a function foo = x -- comment1 where nn = 2
Instances5HasDecls
HasDecls ParsedSourceDefined in ghc-exactprint-1.10.0.0 · Language.Haskell.GHC.ExactPrint.TransformHasDecls (LocatedA (HsDecl GhcPs))Defined in ghc-exactprint-1.10.0.0 · Language.Haskell.GHC.ExactPrint.TransformHasDecls (LocatedA (HsExpr GhcPs))Defined in ghc-exactprint-1.10.0.0 · Language.Haskell.GHC.ExactPrint.TransformHasDecls (LocatedA (Match GhcPs (LocatedA (HsExpr GhcPs))))Defined in ghc-exactprint-1.10.0.0 · Language.Haskell.GHC.ExactPrint.TransformHasDecls (LocatedA (Stmt GhcPs (LocatedA (HsExpr GhcPs))))Defined in ghc-exactprint-1.10.0.0 · Language.Haskell.GHC.ExactPrint.Transform
Extract the immediate declarations for a PatBind. This cannot be a member of HasDecls because a FunBind is not idempotent for hsDecls / replaceDecls. hsDeclsPatBind / replaceDeclsPatBind is idempotent.
Extract the immediate declarations for a PatBind wrapped in a ValD. This cannot be a member of HasDecls because a FunBind is not idempotent for hsDecls / replaceDecls. hsDeclsPatBindD / replaceDeclsPatBindD is idempotent.
Replace the immediate declarations for a PatBind. This cannot be a member of HasDecls because a FunBind is not idempotent for hsDecls / replaceDecls. hsDeclsPatBind / replaceDeclsPatBind is idempotent.
Replace the immediate declarations for a PatBind wrapped in a ValD. This cannot be a member of HasDecls because a FunBind is not idempotent for hsDecls / replaceDecls. hsDeclsPatBindD / replaceDeclsPatBindD is idempotent.
Apply a transformation to the decls contained in t
Utility, does not manage layout
Utility function for returning decls to HsLocalBinds. Use with care, as this does not manage the declaration order, the ordering should be done by the calling function from the HsLocalBinds context in the AST.
New gen functions
Create a SrcSpanAnn with a MovedAnchor operation using the
given DeltaPos.
Managing lists, Transform monad
Insert a declaration into an AST element having sub-declarations
(HasDecls) according to the given location function.
Insert a declaration at the beginning or end of the subdecls of the given AST item
Insert a declaration at the beginning or end of the subdecls of the given AST item
Insert a declaration at a specific location in the subdecls of the given AST item
Insert a declaration at a specific location in the subdecls of the given AST item
Low level operations used in HasDecls
The GHC parser puts all comments appearing between the end of one AST
item and the beginning of the next as annPriorComments for the second one.
This function takes two adjacent AST items and moves any annPriorComments
from the second one to the annFollowingComments of the first if they belong
to it instead. This is typically required before deleting or duplicating
either of the AST elements.
If we compile in haddock mode we get DocDecls, which we strip out while exact printing. Make sure we do not balance any comments on to them be stripping them out here already.
Managing lists, pure functions
Operations
1 declarationTest whether a given SrcSpan was generated by uniqueSrcSpanT
Pure functions
9 declarationsTake the annEntryDelta associated with the first item and associate it with the second. Also transfer any comments occurring before it.
Take the annEntryDelta associated with the first item and associate it with the second. Also transfer any comments occurring before it. TODO: call transferEntryDP, and use pushDeclDP