<div dir="ltr"><div><div><div><div><div><div>Hi Richard,<br><br></div>Thanks for the reply :)</div><div><br></div>I had already tried erl_syntax:form_list/1 on the Forms. The output is:<br><br>21> erl_syntax:form_list(Forms).<br>
{tree,form_list,<br> {attr,0,[],none},<br> [{attribute,1,file,{"../src/eaop_explore/hello.erl",1}},<br> {attribute,1,module,hello},<br> {attribute,2,export,[{send_hello,1},{receive_hello,0}]},<br> {function,4,send_hello,1,<br>
[{clause,4,<br> [{var,4,'To'}],<br> [],<br> [{op,5,'!',<br> {var,5,'To'},<br> {tuple,5,[{atom,5,hello},{call,5,{atom,5,self},[]}]}}]}]},<br>
{function,7,receive_hello,0,<br> [{clause,7,[],[],<br> [{'receive',8,<br> [{clause,9,<br> [{tuple,9,[{atom,9,hello},{var,9,'From'}]}],<br>
[],<br> [{tuple,10,[{atom,10,ok},{var,10,'From'}]}]},<br> {clause,11,<br> [{var,11,'Msg'}],<br> [],<br>
[{tuple,12,<br> [{atom,12,unknown_msg},{var,12,'Msg'}]}]}]}]}]},<br> {eof,13}]}<br><br></div>But, when I did:<br><br>24> module_attr:postorder(module_attr:getAtomFun(), v(21)).<br>
{tree,form_list,<br> {attr,0,[],none},<br> [{tree,attribute,<br> {attr,1,[],none},<br> {attribute,<br> {tree,atom,{attr,0,[],none},a_file},<br> [{tree,string,<br> {attr,1,[],none},<br>
"../src/eaop_explore/hello.erl"},<br> {tree,integer,{attr,1,[],none},1}]}},<br> {tree,attribute,<br> {attr,1,[],none},<br> {attribute,<br> {tree,atom,{attr,1,[],none},module},<br>
[{tree,atom,{attr,0,[],none},a_hello}]}},<br> {tree,attribute,<br> {attr,2,[],none},<br> {attribute,<br> {tree,atom,{attr,2,[],none},export},<br> [{tree,list,<br> {attr,2,[],none},<br>
{list,<br> [{tree,arity_qualifier,<br> {attr,2,[],none},<br> {arity_qualifier,{tree,...},{...}}},<br> {tree,arity_qualifier,<br>
{attr,2,[],...},<br> {arity_qualifier,{...},...}}],<br> none}}]}},<br> {tree,function,<br> {attr,4,[],none},<br> {function,<br>
{tree,atom,{attr,0,[],none},a_send_hello},<br> [{tree,clause,<br> {attr,4,[],none},<br> {clause,<br> [{var,4,'To'}],<br> none,<br>
[{tree,infix_expr,{attr,...},{...}}]}}]}},<br> {tree,function,<br> {attr,7,[],none},<br> {function,<br> {tree,atom,{attr,0,[],none},a_receive_hello},<br> [{tree,clause,<br>
{attr,7,[],none},<br> {clause,[],none,[{tree,receive_expr,{...},...}]}}]}},<br> {eof,13}]}<br><br>and then:<br><br>25> erl_syntax:revert_forms(v(24)).<br>** exception error: {error,<br>
{tree,attribute,<br> {attr,1,[],none},<br> {attribute,<br> {atom,0,a_file},<br> [{string,1,"../src/eaop_explore/hello.erl"},<br>
{integer,1,1}]}}}<br> in function erl_syntax:revert_forms/1 (erl_syntax.erl, line 6648)<br><br></div><div>lol, taking a look at it now I can see what I did... changed the 'file' attribute to 'a_file'... it works if you remove the following (or at least change 'a_file' to 'file')<br>
</div><br>{tree,attribute,<br> {attr,1,[],none},<br> {attribute,<br> {tree,atom,{attr,0,[],none},a_file},<br> [{tree,string,{attr,1,[],none},"../src/eaop_explore/hello.erl"},<br> {tree,integer,{attr,1,[],none},1}]}},<br>
<br></div>How stupid of me ^^;<br><br></div><div>Already came across the same problem with the 'export' and 'module' attributes just 30 mins or so ago. Thanks for the help!!<br><br></div><div>Regards,<br></div>
<div>Justin<br></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On 7 February 2013 15:03, Richard Carlsson <span dir="ltr"><<a href="mailto:carlsson.richard@gmail.com" target="_blank">carlsson.richard@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">On 02/07/2013 02:55 PM, Justin Calleja wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
I would like to use the postorder/2 function in the comments of erl_syntax:<br>
<br>
postorder(F, Tree) -><br>
F(case erl_syntax:subtrees(Tree) of<br>
[] -> Tree;<br>
List -> erl_syntax:update_tree(Tree,<br>
[[postorder(F, Subtree)<br>
|| Subtree <- Group]<br>
|| Group <- List])<br>
end).<br>
<br>
to traverse a syntax tree and do some kind of manipulation.<br>
<br>
The problems is that, although the documentation (or how I understood<br>
the doc anyway) claims that abstract forms are a subset of syntax trees,<br>
</blockquote>
<br></div>
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.<span class="HOEnZb"><font color="#888888"><br>
<br>
/Richard<br>
<br>
</font></span></blockquote></div><br></div>