Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Synopsis
- data Retrie a
- addImports :: AnnotatedImports -> Retrie ()
- apply :: [Rewrite Universe] -> Retrie ()
- applyWithStrategy :: Strategy (TransformT (WriterT Change IO)) -> [Rewrite Universe] -> Retrie ()
- applyWithUpdate :: ContextUpdater -> [Rewrite Universe] -> Retrie ()
- applyWithUpdateAndStrategy :: ContextUpdater -> Strategy (TransformT (WriterT Change IO)) -> [Rewrite Universe] -> Retrie ()
- focus :: Data k => [Query k v] -> Retrie ()
- ifChanged :: Retrie () -> Retrie () -> Retrie ()
- iterateR :: Int -> Retrie () -> Retrie ()
- query :: [Query Universe v] -> Retrie [(Context, Substitution, v)]
- queryWithUpdate :: ContextUpdater -> [Query Universe v] -> Retrie [(Context, Substitution, v)]
- topDownPrune :: Monad m => Strategy (TransformT (WriterT Change m))
- getGroundTerms :: Retrie a -> [GroundTerms]
- liftRWST :: RetrieComp a -> Retrie a
- runRetrie :: FixityEnv -> Retrie a -> CPP AnnotatedModule -> IO (a, CPP AnnotatedModule, Change)
Retrie Computations
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
.
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.
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.