Bunch v0.3.0 Bunch.Macro View Source
A bunch of helpers for implementing macros.
Link to this section Summary
Functions
Receives an AST and traverses it expanding all the nodes
Imitates import
functionality by finding and replacing bare function
calls (like foo()
) in AST with fully-qualified call (like Some.Module.foo()
)
Imitates import
functionality by finding and replacing bare function
calls (like foo()
) in AST with fully-qualified call (like Some.Module.foo()
)
Works like Macro.prewalk/2
, but allows to skip particular nodes
Link to this section Functions
expand_deep(ast, env) View Source
Receives an AST and traverses it expanding all the nodes.
This function uses Macro.expand/2
under the hood. Check
it out for more information and examples.
inject_call(ast, arg) View Source
Imitates import
functionality by finding and replacing bare function
calls (like foo()
) in AST with fully-qualified call (like Some.Module.foo()
)
Receives AST fragment as first parameter and a pair {Some.Module, :foo} as second
inject_calls(ast, functions) View Source
Imitates import
functionality by finding and replacing bare function
calls (like foo()
) in AST with fully-qualified call (like Some.Module.foo()
)
Receives AST fragment as first parameter and list of pairs {Some.Module, :foo} as second
prewalk_while(ast, fun) View Source
Works like Macro.prewalk/2
, but allows to skip particular nodes.
Example
iex> code = quote do fun(1, 2, opts: [key: :val]) end
iex> code |> Bunch.Macro.prewalk_while(fn node ->
...> if Keyword.keyword?(node) do
...> {:skip, node ++ [default: 1]}
...> else
...> {:enter, node}
...> end
...> end)
quote do fun(1, 2, opts: [key: :val], default: 1) end