[erlang-questions] erl_syntax:revert with binary arg
Magnus Henoch
magnus.henoch@REDACTED
Thu Sep 6 15:41:26 CEST 2012
Max Kuznecov <mek@REDACTED> writes:
> I'm creating some dynamic module generation stuff and I found a
> strange behavior,
> erl_syntax:revert doesn't seem to work with binaries:
>
> It works with strings (and other types)
>
>> erl_syntax:revert(erl_syntax:string("DATA")).
> {string,0,"DATA"}
>
> but
>
>> erl_syntax:revert(erl_syntax:binary(<<"DATA">>)).
> ** exception error: no function clause matching
> erl_syntax:'-revert/1-lc$^1/1-1-'(<<"DATA">>)
> (erl_syntax.erl, line 6508)
> in function erl_syntax:'-revert/1-lc$^0/1-0-'/1 (erl_syntax.erl,
> line 6508)
> in call from erl_syntax:revert/1 (erl_syntax.erl, line 6508)
>
> Is there any special trick to handle binaries in revert()?
It seems like erl_syntax:binary(<<"DATA">>) is not the right way to
create an abstract representation of a binary literal - it's different
from what erl_syntax:abstract returns:
1> erl_syntax:abstract(<<"DATA">>).
{tree,binary,
{attr,0,[],none},
[{tree,binary_field,
{attr,0,[],none},
{binary_field,{tree,integer,{attr,0,[],none},68},[]}},
{tree,binary_field,
{attr,0,[],none},
{binary_field,{tree,integer,{attr,0,[],none},65},[]}},
{tree,binary_field,
{attr,0,[],none},
{binary_field,{tree,integer,{attr,0,[],none},84},[]}},
{tree,binary_field,
{attr,0,[],none},
{binary_field,{tree,integer,{attr,0,[],none},65},[]}}]}
2> erl_syntax:binary(<<"DATA">>).
{tree,binary,{attr,0,[],none},<<"DATA">>}
3> erl_syntax:revert(v(1)).
{bin,0,
[{bin_element,0,{integer,0,68},default,default},
{bin_element,0,{integer,0,65},default,default},
{bin_element,0,{integer,0,84},default,default},
{bin_element,0,{integer,0,65},default,default}]}
Regards,
Magnus
More information about the erlang-questions
mailing list