retrie-1.2.2: A powerful, easy-to-use codemodding tool for Haskell.

Safe Haskell | Safe-Inferred
Language | Haskell2010

Retrie.ExactPrint.Annotated

Contents

- Annotated
  - Synonyms
  - Operations
- Internal

Synopsis

- data Annotated ast
- astA :: Annotated ast -> ast
- seedA :: Annotated ast -> Int
- type AnnotatedHsDecl = Annotated (LHsDecl GhcPs)
- type AnnotatedHsExpr = Annotated (LHsExpr GhcPs)
- type AnnotatedHsType = Annotated (LHsType GhcPs)
- type AnnotatedImport = Annotated (LImportDecl GhcPs)
- type AnnotatedImports = Annotated [LImportDecl GhcPs]
- type AnnotatedModule = Annotated (Located (HsModule GhcPs))
- type AnnotatedPat = Annotated (LPat GhcPs)
- type AnnotatedStmt = Annotated (LStmt GhcPs (LHsExpr GhcPs))
- pruneA :: (Data ast, Monad m) => ast -> TransformT m (Annotated ast)
- graftA :: (Data ast, Monad m) => Annotated ast -> TransformT m ast
- transformA :: Monad m => Annotated ast1 -> (ast1 -> TransformT m ast2) -> m (Annotated ast2)
- trimA :: Data ast => Annotated ast -> Annotated ast
- setEntryDPA :: Default an => Annotated (LocatedAn an ast) -> DeltaPos -> Annotated (LocatedAn an ast)
- printA :: (Data ast, ExactPrint ast) => Annotated ast -> String
- printA' :: (Data ast, ExactPrint ast) => Annotated ast -> String
- showAstA :: (Data ast, ExactPrint ast) => Annotated ast -> String
- unsafeMkA :: ast -> Int -> Annotated ast

# Annotated

data Annotated ast #

`Annotated` packages an AST fragment with the annotations necessary to `exactPrint` or `transform` that AST.

#### Instances

Instances details

Foldable Annotated # |

Instance details

Defined in Retrie.ExactPrint.Annotated

Methods

fold :: Monoid m => Annotated m -> m

foldMap :: Monoid m => (a -> m) -> Annotated a -> m

foldMap' :: Monoid m => (a -> m) -> Annotated a -> m

foldr :: (a -> b -> b) -> b -> Annotated a -> b

foldr' :: (a -> b -> b) -> b -> Annotated a -> b

foldl :: (b -> a -> b) -> b -> Annotated a -> b

foldl' :: (b -> a -> b) -> b -> Annotated a -> b

foldr1 :: (a -> a -> a) -> Annotated a -> a

foldl1 :: (a -> a -> a) -> Annotated a -> a

toList :: Annotated a -> [a]

null :: Annotated a -> Bool

length :: Annotated a -> Int

elem :: Eq a => a -> Annotated a -> Bool

maximum :: Ord a => Annotated a -> a

minimum :: Ord a => Annotated a -> a

sum :: Num a => Annotated a -> a

product :: Num a => Annotated a -> a

Traversable Annotated # |
Instance details Defined in Retrie.ExactPrint.Annotated Methods traverse :: Applicative f => (a -> f b) -> Annotated a -> f (Annotated b) sequenceA :: Applicative f => Annotated (f a) -> f (Annotated a) mapM :: Monad m => (a -> m b) -> Annotated a -> m (Annotated b) sequence :: Monad m => Annotated (m a) -> m (Annotated a)
Functor Annotated # |
Instance details Defined in Retrie.ExactPrint.Annotated Methods fmap :: (a -> b) -> Annotated a -> Annotated b # (<$) :: a -> Annotated b -> Annotated a #
Data ast => Data (Annotated ast) # |

Instance details

Defined in Retrie.ExactPrint.Annotated

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Annotated ast -> c (Annotated ast) #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (Annotated ast) #

toConstr :: Annotated ast -> Constr #

dataTypeOf :: Annotated ast -> DataType #

dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c (Annotated ast)) #

dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Annotated ast)) #

gmapT :: (forall b. Data b => b -> b) -> Annotated ast -> Annotated ast #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Annotated ast -> r #

gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Annotated ast -> r #

gmapQ :: (forall d. Data d => d -> u) -> Annotated ast -> [u] #

gmapQi :: Int -> (forall d. Data d => d -> u) -> Annotated ast -> u #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> Annotated ast -> m (Annotated ast) #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Annotated ast -> m (Annotated ast) #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Annotated ast -> m (Annotated ast) #

(Data ast, Monoid ast) => Monoid (Annotated ast) # |
Instance details Defined in Retrie.ExactPrint.Annotated Methods mempty :: Annotated ast mappend :: Annotated ast -> Annotated ast -> Annotated ast # mconcat :: [Annotated ast] -> Annotated ast
(Data ast, Monoid ast) => Semigroup (Annotated ast) # |
Instance details Defined in Retrie.ExactPrint.Annotated Methods (<>) :: Annotated ast -> Annotated ast -> Annotated ast # sconcat :: NonEmpty (Annotated ast) -> Annotated ast stimes :: Integral b => b -> Annotated ast -> Annotated ast
Default ast => Default (Annotated ast) # |
Instance details Defined in Retrie.ExactPrint.Annotated Methods def :: Annotated ast #

astA :: Annotated ast -> ast #

Examine the actual AST.

seedA :: Annotated ast -> Int #

Name supply used by ghc-exactprint to generate unique locations.

## Synonyms

type AnnotatedHsDecl = Annotated (LHsDecl GhcPs) #

type AnnotatedHsExpr = Annotated (LHsExpr GhcPs) #

type AnnotatedHsType = Annotated (LHsType GhcPs) #

type AnnotatedImport = Annotated (LImportDecl GhcPs) #

type AnnotatedImports = Annotated [LImportDecl GhcPs] #

type AnnotatedModule = Annotated (Located (HsModule GhcPs)) #

type AnnotatedPat = Annotated (LPat GhcPs) #

type AnnotatedStmt = Annotated (LStmt GhcPs (LHsExpr GhcPs)) #

## Operations

pruneA :: (Data ast, Monad m) => ast -> TransformT m (Annotated ast) #

Encapsulate something in the current transformation into an `Annotated` thing. This is the inverse of `graftT`. For example:

    splitHead :: Monad m => Annotated [a] -> m (Annotated a, Annotated [a])
    splitHead l = fmap astA $ transformA l $ \(x:xs) -> do
      y <- pruneA x
      ys <- pruneA xs
      return (y, ys)

graftA :: (Data ast, Monad m) => Annotated ast -> TransformT m ast #

Graft an `Annotated` thing into the current transformation. The resulting AST will have proper annotations within the `TransformT` computation. For example:

    mkDeclList :: IO (Annotated [LHsDecl GhcPs])
    mkDeclList = do
      ad1 <- parseDecl "myId :: a -> a"
      ad2 <- parseDecl "myId x = x"
      transformA ad1 $ \ d1 -> do
        d2 <- graftA ad2
        return [d1, d2]

transformA :: Monad m => Annotated ast1 -> (ast1 -> TransformT m ast2) -> m (Annotated ast2) #

Transform an `Annotated` thing.

trimA :: Data ast => Annotated ast -> Annotated ast #

Trim the annotation data to only include annotations for `ast`. (Usually, the annotation data is a superset of what is necessary.) Also freshens all source locations, so filename information in annotation keys is discarded.

Note: not commonly needed, but useful if you want to inspect the annotation data directly and don't want to wade through a mountain of output.

setEntryDPA :: Default an => Annotated (LocatedAn an ast) -> DeltaPos -> Annotated (LocatedAn an ast) #

printA :: (Data ast, ExactPrint ast) => Annotated ast -> String #

Exactprint an `Annotated` thing.

printA' :: (Data ast, ExactPrint ast) => Annotated ast -> String #

showAstA :: (Data ast, ExactPrint ast) => Annotated ast -> String #

showAst an `Annotated` thing.

# Internal

unsafeMkA :: ast -> Int -> Annotated ast #

Construct an `Annotated`. This should really only be used in the parsing functions, hence the scary name. Don't use this unless you know what you are doing.