[erlang-questions] Erlang AST with locations

Robert Virding <>
Wed Oct 10 21:29:44 CEST 2007


On 05/10/2007, Joel Reymont <> wrote:
>
> The result of erl_scan:string/1 has line numbers in it but these get
> lost once erl_parse:parse/1 runs.
>
> I would like to have an AST with locations, is there a way to
> accomplish that?


Sorry I don't really understand what you mean. If you do

28> {ok,Ts,_}=erl_scan:string("abc([a])->\n1.").
{ok,[{atom,1,abc},
     {'(',1},
     {'[',1},
     {atom,1,a},
     {']',1},
     {')',1},
     {'->',1},
     {integer,2,1},
     {dot,2}],
    2}
29> erl_parse:parse(Ts).
{ok,{function,1,
              abc,
              1,

[{clause,1,[{cons,1,{atom,1,a},{nil,1}}],[],[{integer,2,1}]}]}}

you that you do have the line numbers in the AST. If you use parse_term,
however, line numbers are removed as it is the term which returned not the
AST.

On a related note, I think it's a bummer that there's no
> erl_scan:binary/1.


True, true. One of these years ...

Robert
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20071010/70707a6b/attachment.html>


More information about the erlang-questions mailing list