View Source merlin_lib (merlin v3.0.1)

Helpers for working with erl_syntax:syntaxTree().

Similar to erl_syntax_lib, but with a different set of helpers, and a preference for returning maps over proplists.

Summary

Functions

Returns the first Node that satisfies the given function, or {error, notfound} if no such Node is found.

Return the first Node that satisfies the given function, or {error, notfound} if no such form is found.

Returns a flat list of nodes from the given form list or list of nodes.
Returns true if the given syntax node is a erl_syntax node, false otherwise.
Calls the given function with the forms inside the given Result, while preserving any errors and/or warnings.

Updates the given node using the given groups or subtrees of another node.

Returns the value of the given literal node as an Erlang term.

Types

-type predicate() :: predicate(merlin:ast()).
-type predicate(T) :: fun((T) -> boolean()).

Functions

Link to this function

deep_find_by(Forms0, Predicate)

View Source
-spec deep_find_by(merlin:ast() | [merlin:ast()], predicate()) -> {ok, merlin:ast()} | {error, notfound}.

Returns the first Node that satisfies the given function, or {error, notfound} if no such Node is found.

The search is performed recursively.
-spec find_by([merlin:ast()], predicate(Node)) -> {ok, Node} | {error, notfound}
           when Node :: merlin:ast().

Return the first Node that satisfies the given function, or {error, notfound} if no such form is found.

The search is performed shallowly.

See also: deep_find_by/2.

-spec flatten(NodeOrNodes) -> [merlin:ast()] when NodeOrNodes :: merlin:ast() | [NodeOrNodes].
Returns a flat list of nodes from the given form list or list of nodes.
-spec is_erl_syntax(merlin:erl_syntax_ast()) -> true;
             (merlin:erl_parse()) -> false.
Returns true if the given syntax node is a erl_syntax node, false otherwise.
-spec then(Result, fun((Forms) -> Forms)) -> Result
        when Result :: merlin:parse_transform_return(Forms), Forms :: [merlin:ast()].
Calls the given function with the forms inside the given Result, while preserving any errors and/or warnings.
Link to this function

update_tree(Node, Groups)

View Source
-spec update_tree(merlin:ast(), [[merlin:ast()]] | merlin:ast()) -> merlin:ast().

Updates the given node using the given groups or subtrees of another node.

This is a generalisation of erl_syntax:update_tree/2.
-spec value(merlin:ast()) -> term().

Returns the value of the given literal node as an Erlang term.

Raises {badvalue, Node} if the given Node is not an literal node.