[erlang-questions] Parse-transforming !! to a function call

Philip Robinson chlorophil@REDACTED
Sun Aug 12 01:52:08 CEST 2007


On 8/12/07, Joel Reymont <joelr1@REDACTED> wrote:
> I would like x !! y to be transformed into mod:func(x, y). Is this
> possible?

AFAIK a parse_transform can only work on a legal AST.

x !! y is not turned into a valid AST via c(module).


-module(show_ast).
-export([parse_transform/2]).
parse_transform(AST, _Options) ->
    [io:format("~p~n", [Node]) || Node <- AST],
    AST.


-module(test).
-compile([export_all]).
-compile({parse_transform, show_ast}).
test() -> x !! y.


1> c(show_ast), c(test).
{attribute,1,file,{"./test.erl",1}}
{attribute,1,module,test}
{attribute,2,compile,[export_all]}
{error,{5,erl_parse,["syntax error before: ",["'!'"]]}}
{eof,7}
./test.erl:5: syntax error before: '!'
error
2>

i.e.: An error is produced before show_ast can do anything about it.

I do not know if it would be possible to get around this by using any
of the various Erlang parse tools.  (If you do find a way then please
let me know!)

Cheers,
Philip



More information about the erlang-questions mailing list