retrie-1.1.0.0: A powerful, easy-to-use codemodding tool for Haskell.
Safe HaskellNone
LanguageHaskell2010

Retrie.ExactPrint.Annotated

Synopsis

Annotated

data Annotated ast Source #

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

Instances

Instances details
Functor Annotated Source # 
Instance details

Defined in Retrie.ExactPrint.Annotated

Methods

fmap :: (a -> b) -> Annotated a -> Annotated b #

(<$) :: a -> Annotated b -> Annotated a #

Foldable Annotated Source # 
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 Source # 
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) #

(Data ast, Monoid ast) => Semigroup (Annotated ast) Source # 
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 #

(Data ast, Monoid ast) => Monoid (Annotated ast) Source # 
Instance details

Defined in Retrie.ExactPrint.Annotated

Methods

mempty :: Annotated ast #

mappend :: Annotated ast -> Annotated ast -> Annotated ast #

mconcat :: [Annotated ast] -> Annotated ast #

Default ast => Default (Annotated ast) Source # 
Instance details

Defined in Retrie.ExactPrint.Annotated

Methods

def :: Annotated ast #

astA :: Annotated ast -> ast Source #

Examine the actual AST.

annsA :: Annotated ast -> Anns Source #

Annotations generated/consumed by ghc-exactprint

seedA :: Annotated ast -> Int Source #

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

Synonyms

Operations

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

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 Source #

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) Source #

Transform an Annotated thing.

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

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.

printA :: Annotate ast => Annotated (Located ast) -> String Source #

Exactprint an Annotated thing.

Internal

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

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.