exmen v0.1.0 Exmen.Discover.Middleware

Abstraction layer to help travere an AST and interact with Mutation middleware

Summary

Functions

Start AST traversal

Functions

run(ast, mutate)

Start AST traversal.

mutation

The mutate function gets called with every node in the AST. This allows the middleware to manipulate nodes and change the control flow. The accepted return values are:

  • {:ok, mutated_node, next_node}
  • {:skip, node}
  • any other value gets ignored

Examples

iex> alias Exmen.Discover.Middleware
iex> mutator = fn node ->
iex>   case node do
iex>     {:+, meta, args} -> {:ok, {:-, meta, args}, args}
iex>     {:-, _, _}       -> {:skip, node}
iex>     _                -> nil
iex>   end
iex> end
iex> [mutation] = Middleware.run(quote(do: 1 - 1 + 2), mutator)
iex> elem(mutation, 0)
:-