<div dir="ltr"><div class="gmail_signature">This is a good opportunity to demonstrate the function erl_syntax:meta/1 (using merl in OTP 18 to simplify building the AST):<br><br></div><div class="gmail_signature">1> AST=merl:quote("-import(mymdule, [test1/0, test2/0])").</div><div class="gmail_signature">2> io:put_chars(erl_prettypr:format(erl_syntax:meta(AST))).<br><br>erl_syntax:make_tree(prefix_expr,<br>                     [[erl_syntax:operator('-')],<br>                      [erl_syntax:make_tree(application,<br>                                            [[erl_syntax:atom(import)],<br>                                             [erl_syntax:atom(mymdule),<br>                                              erl_syntax:list([erl_syntax:make_tree(infix_expr,<br>                                                                                    [[erl_syntax:atom(test1)],<br>                                                                                     [erl_syntax:operator('/')],<br>                                                                                     [erl_syntax:integer(0)]]),<br>                                                               erl_syntax:make_tree(infix_expr,<br>                                                                                    [[erl_syntax:atom(test2)],<br>                                                                                     [erl_syntax:operator('/')],<br>                                                                                     [erl_syntax:integer(0)]])])]])]])<br><br></div><div class="gmail_signature">There's also the useful function merl:show/1 for inspecting the basic structure of an AST:<br><br>3> merl:show(AST).<br><br>prefix_expr: -import(mymdule, [...])<br>  operator: -<br>  +<br>  application: import(mymdule, [test1 / 0, test2 / 0])<br>    atom: import<br>    +<br>    atom: mymdule<br>    list: [test1 / 0, test2 / 0]<br>      infix_expr: test1 / 0<br>        atom: test1<br>        +<br>        operator: /<br>        +<br>        integer: 0<br>      infix_expr: test2 / 0<br>        atom: test2<br>        +<br>        operator: /<br>        +<br>        integer: 0<br><br></div><div class="gmail_signature"><br>    /Richard</div><div class="gmail_extra">
<br><div class="gmail_quote">On Tue, Jul 14, 2015 at 3:08 PM, Humberto Rodríguez Avila <span dir="ltr"><<a href="mailto:h87rguez@gmail.com" target="_blank">h87rguez@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><span style="color:rgb(0,0,0);font-family:Helvetica;font-size:12px">Hello guys!</span><div style="color:rgb(0,0,0);font-family:Helvetica;font-size:12px"><br></div><div style="color:rgb(0,0,0);font-family:Helvetica;font-size:12px">  I am a new programming in Erlang and I interested in doing things with meta-programming. I have been working with merl and I did a couple of examples (module generation). Nevertheless, I have been trying to do the same thing using erl_syntax, but I can’t found how to <span>build</span> the <span>syntax tree</span> of the directive -<span>import</span> :(</div><div style="color:rgb(0,0,0);font-family:Helvetica;font-size:12px"><br></div><div style="color:rgb(0,0,0);font-family:Helvetica;font-size:12px">For example: <span> -import(mymdule, [test1/0, test2/0])</span></div><div style="color:rgb(0,0,0);font-family:Helvetica;font-size:12px"><br></div><div style="color:rgb(0,0,0);font-family:Helvetica;font-size:12px">Any suggestion?</div><div style="color:rgb(0,0,0);font-family:Helvetica;font-size:12px"><br></div><div style="color:rgb(0,0,0);font-family:Helvetica;font-size:12px">Thanks in advance!</div><span class=""><font color="#888888"><div style="color:rgb(0,0,0);font-family:Helvetica;font-size:12px"><br><div>--- Humberto</div></div></font></span></div>
<br>_______________________________________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>
<a href="http://erlang.org/mailman/listinfo/erlang-questions" rel="noreferrer" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br>
<br></blockquote></div><br></div></div>