retrie-1.2.3: A powerful, easy-to-use codemodding tool for Haskell.
Safe HaskellSafe-Inferred
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
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) #

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

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.

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 :: (Data ast, ExactPrint ast) => Annotated ast -> String Source #

Exactprint an Annotated thing.

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

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

showAst an Annotated thing.

Internal

unsafeMkA :: ast -> 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.