identity parse transform using syntax_tools
Ulf Wiger (AL/EAB)
ulf.wiger@REDACTED
Mon Feb 13 14:40:18 CET 2006
I thought this might be of some use to those out there
writing parse transforms.
I simplified my plain_fsm_xform module into an entity
parse transform callback.
The main point is of course that a parse transform
based on syntax_tools should be much more stable
in time than cloning erl_id_trans and hacking it.
The actual work is done in a fun:
Fun = fun(Type, Form, Context, Acc) ->
io:format("Type = ~p~n"
"Form = ~p~n"
"Context = ~p~n"
"Acc = ~p~n", [Type, Form, Context,
Acc]),
{Form, _Recurse = true, Acc+1}
end,
and the parse_transform callback looks like this:
parse_transform(Forms, _Options) ->
Fun = fun(Type, Form, Context, Acc) ->
...
end,
{NewTree, _} = transform(Forms, Fun, _Acc = 1),
[erl_syntax:revert(T) || T <- lists:flatten(NewTree)].
The Recurse flag can be set to false if there is
no need to traverse the subtrees of a particular
form. Perhaps an unnecessary optimization...
I haven't tested it much - basically just compiling
a module and checking that the printouts look ok.
I've attached the module. Let me know what you think.
Regards,
Ulf W
-------------- next part --------------
A non-text attachment was scrubbed...
Name: stools_id_trans.erl
Type: application/octet-stream
Size: 3163 bytes
Desc: stools_id_trans.erl
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20060213/90755f21/attachment.obj>
More information about the erlang-questions
mailing list