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

Safe HaskellNone
LanguageHaskell2010

Retrie.Monad

Contents

Synopsis

Retrie Computations

data Retrie a Source #

The Retrie monad is essentially IO, plus state containing the module that is being transformed. It is run once per target file.

It is special because it also allows Retrie to extract a set of GroundTerms from the Retrie computation without evaluating it.

Retrie uses the ground terms to select which files to target. This is the key optimization that allows Retrie to handle large codebases.

Note: Due to technical limitations, we cannot extract ground terms if you use liftIO before calling one of apply, focus, or query at least once. This will cause Retrie to attempt to parse every module in the target directory. In this case, please add a call to focus before the call to liftIO.

Instances
Monad Retrie Source # 
Instance details

Defined in Retrie.Monad

Methods

(>>=) :: Retrie a -> (a -> Retrie b) -> Retrie b #

(>>) :: Retrie a -> Retrie b -> Retrie b #

return :: a -> Retrie a #

fail :: String -> Retrie a #

Functor Retrie Source # 
Instance details

Defined in Retrie.Monad

Methods

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

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

Applicative Retrie Source # 
Instance details

Defined in Retrie.Monad

Methods

pure :: a -> Retrie a #

(<*>) :: Retrie (a -> b) -> Retrie a -> Retrie b #

liftA2 :: (a -> b -> c) -> Retrie a -> Retrie b -> Retrie c #

(*>) :: Retrie a -> Retrie b -> Retrie b #

(<*) :: Retrie a -> Retrie b -> Retrie a #

MonadIO Retrie Source # 
Instance details

Defined in Retrie.Monad

Methods

liftIO :: IO a -> Retrie a #

addImports :: AnnotatedImports -> Retrie () Source #

Add imports to the module.

apply :: [Rewrite Universe] -> Retrie () Source #

Apply a set of rewrites. By default, rewrites are applied top-down, pruning the traversal at successfully changed AST nodes. See topDownPrune.

applyWithStrategy :: Strategy (TransformT (WriterT Change IO)) -> [Rewrite Universe] -> Retrie () Source #

Apply a set of rewrites with a custom traversal strategy.

applyWithUpdate :: ContextUpdater -> [Rewrite Universe] -> Retrie () Source #

Apply a set of rewrites with a custom context-update function.

applyWithUpdateAndStrategy :: ContextUpdater -> Strategy (TransformT (WriterT Change IO)) -> [Rewrite Universe] -> Retrie () Source #

Apply a set of rewrites with custom context-update and traversal strategy.

focus :: Data k => [Query k v] -> Retrie () Source #

Use the given queries/rewrites to select files for rewriting. Does not actually perform matching. This is useful if the queries/rewrites which best determine which files to target are not the first ones you run, and when you need to liftIO before running any queries/rewrites.

ifChanged :: Retrie () -> Retrie () -> Retrie () Source #

If the first Retrie computation makes a change to the module, run the second Retrie computation.

iterateR :: Int -> Retrie () -> Retrie () Source #

Iterate given Retrie computation until it no longer makes changes, or N times, whichever happens first.

query :: [Query Universe v] -> Retrie [(Context, Substitution, v)] Source #

Query the AST. Each match returns the context of the match, a substitution mapping quantifiers to matched subtrees, and the query's value.

queryWithUpdate :: ContextUpdater -> [Query Universe v] -> Retrie [(Context, Substitution, v)] Source #

Query the AST with a custom context update function.

topDownPrune :: Monad m => Strategy (TransformT (WriterT Change m)) Source #

Top-down traversal that does not descend into changed AST nodes. Default strategy used by apply.

Internal

getGroundTerms :: Retrie a -> [GroundTerms] Source #

Helper to extract the ground terms from a Retrie computation.

liftRWST :: RetrieComp a -> Retrie a Source #