[erlang-questions] erl_sytanx help

Richard Carlsson carlsson.richard@REDACTED
Thu Jul 16 14:20:58 CEST 2015


There should in most cases be no overhead using merl compared to using
erl_syntax directly. In particular, whatever code you _generate_ using merl
will be no different from what you would construct through calls to
erl_syntax. If there is any overhead, it will be during code generation.
You can inspect the Erlang code that merl creates by using erlc +"'P'"
(note the extra quotes) or calling compile:file(foo, ['P']).

        /Richard

On Wed, Jul 15, 2015 at 12:23 AM, Humberto Rodriguez <
humbert.rguez@REDACTED> wrote:

> Richard, thanks for the example!
>
> I have another question: How much is the penalty (performance) of use this
> way? I am thinking use erlang as base language to make a DSL on top of Riak
> KV.
>
> Do you have some advice for me? What is the way that you recommend me,
> merl or erl_syntax?
>
> Best regards,
> --- Humberto
>
>
>
> On 15 Jul 2015, at 00:02, Richard Carlsson <carlsson.richard@REDACTED>
> wrote:
>
> This is a good opportunity to demonstrate the function erl_syntax:meta/1
> (using merl in OTP 18 to simplify building the AST):
>
> 1> AST=merl:quote("-import(mymdule, [test1/0, test2/0])").
> 2> io:put_chars(erl_prettypr:format(erl_syntax:meta(AST))).
>
> erl_syntax:make_tree(prefix_expr,
>                      [[erl_syntax:operator('-')],
>                       [erl_syntax:make_tree(application,
>                                             [[erl_syntax:atom(import)],
>                                              [erl_syntax:atom(mymdule),
>
> erl_syntax:list([erl_syntax:make_tree(infix_expr,
>
> [[erl_syntax:atom(test1)],
>
> [erl_syntax:operator('/')],
>
> [erl_syntax:integer(0)]]),
>
> erl_syntax:make_tree(infix_expr,
>
> [[erl_syntax:atom(test2)],
>
> [erl_syntax:operator('/')],
>
> [erl_syntax:integer(0)]])])]])]])
>
> There's also the useful function merl:show/1 for inspecting the basic
> structure of an AST:
>
> 3> merl:show(AST).
>
> prefix_expr: -import(mymdule, [...])
>   operator: -
>   +
>   application: import(mymdule, [test1 / 0, test2 / 0])
>     atom: import
>     +
>     atom: mymdule
>     list: [test1 / 0, test2 / 0]
>       infix_expr: test1 / 0
>         atom: test1
>         +
>         operator: /
>         +
>         integer: 0
>       infix_expr: test2 / 0
>         atom: test2
>         +
>         operator: /
>         +
>         integer: 0
>
>
>     /Richard
>
> On Tue, Jul 14, 2015 at 3:08 PM, Humberto Rodríguez Avila <
> h87rguez@REDACTED> wrote:
>
>> Hello guys!
>>
>>   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 build the syntax
>> tree of the directive -import :(
>>
>> For example:  -import(mymdule, [test1/0, test2/0])
>>
>> Any suggestion?
>>
>> Thanks in advance!
>>
>> --- Humberto
>>
>> _______________________________________________
>> erlang-questions mailing list
>> erlang-questions@REDACTED
>> http://erlang.org/mailman/listinfo/erlang-questions
>>
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20150716/564c75f1/attachment.htm>


More information about the erlang-questions mailing list