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

Safe Haskell | Safe-Inferred
Language | Haskell2010

Retrie.Run

Synopsis

- runScript :: LibDir -> (Options -> IO (Retrie ())) -> IO ()
- runScriptWithModifiedOptions :: LibDir -> (Options -> IO (Options, Retrie ())) -> IO ()
- execute :: LibDir -> Options -> Retrie () -> IO ()
- run :: Monoid b => LibDir -> (FilePath -> WriteFn a b) -> (IO b -> IO c) -> Options -> Retrie a -> IO [c]
- type WriteFn a b = [Replacement] -> String -> CPP AnnotatedModule -> a -> IO b
- writeCountLines :: FilePath -> WriteFn a (Sum Int)
- writeDiff :: Options -> FilePath -> WriteFn a (Sum Int)
- writeSearch :: Options -> FilePath -> WriteFn a ()
- writeExtract :: Options -> FilePath -> WriteFn a ()

# Documentation

runScript :: LibDir -> (Options -> IO (Retrie ())) -> IO () #

Define a custom refactoring script. A script is an `IO` action that defines a `Retrie` computation. The `IO` action is run once, and the resulting `Retrie` computation is run once for each target file. Typically, rewrite parsing/construction is done in the `IO` action, so it is performed only once. Example:

    module Main where

    main :: IO ()
    main = runScript $ \opts -> do
      rr <- parseRewrites opts ["forall f g xs. map f (map g xs) = map (f . g) xs"]
      return $ apply rr

To run the script, compile the program and execute it.

runScriptWithModifiedOptions :: LibDir -> (Options -> IO (Options, Retrie ())) -> IO () #

Define a custom refactoring script and run it with modified options. This is the same as `runScript`, but the returned `Options` will be used during rewriting.

execute :: LibDir -> Options -> Retrie () -> IO () #

Implements retrie's iteration and execution modes.

run #

Arguments

:: Monoid b |
=> LibDir |
-> (FilePath -> WriteFn a b) | write action when a file changes, unchanged files result in `mempty`
-> (IO b -> IO c) | wrap per-file rewrite action
-> Options |
-> Retrie a |
-> IO [c] |

Primitive means of running a `Retrie` computation.

type WriteFn a b = [Replacement] -> String -> CPP AnnotatedModule -> a -> IO b #

Callback function to actually write the resulting file back out. Is given list of changed spans, module contents, and user-defined data.

writeCountLines :: FilePath -> WriteFn a (Sum Int) #

Write action which counts changed lines using `diff`

writeDiff :: Options -> FilePath -> WriteFn a (Sum Int) #

Print the lines before replacement and after replacement.

writeSearch :: Options -> FilePath -> WriteFn a () #

Print lines that match the query and highligh the matched string.

writeExtract :: Options -> FilePath -> WriteFn a () #

Print only replacement.