[erlang-questions] How to get syntax tree out of abstract forms?
Thu Feb 7 15:03:56 CET 2013
On 02/07/2013 02:55 PM, Justin Calleja wrote:
> I would like to use the postorder/2 function in the comments of erl_syntax:
> postorder(F, Tree) ->
> F(case erl_syntax:subtrees(Tree) of
>  -> Tree;
> List -> erl_syntax:update_tree(Tree,
> [[postorder(F, Subtree)
> || Subtree <- Group]
> || Group <- List])
> to traverse a syntax tree and do some kind of manipulation.
> The problems is that, although the documentation (or how I understood
> the doc anyway) claims that abstract forms are a subset of syntax trees,
Yes, an abstract form is also an AST that can be used with e.g.
erl_syntax:subtrees(). However, a *list* of abstract forms is not a
tree. What you can do is to give your list to erl_syntax:form_list(Fs)
to get a single AST that represents all the forms, and then pass that
tree to your traversal function.
More information about the erlang-questions