parse transform options

3 views
Skip to first unread message

Serge

unread,
Jul 20, 2021, 1:35:25 PMJul 20
to Erlang Questions
How do you pass options (2nd argument) to a parse transform?

Documentation (http://erlang.org/doc/man/erl_id_trans.html#parse_transform-2) states that a custom parse transform module should export function that takes two parameters:

parse_transform(Tree, Options) ->
   ...

but there doesn't seem to be a way to pass the transform options from the compiler, i.e.:

erlc +'{parse_transform,Module}' File.erl

What am I missing?

Mikael Karlsson

unread,
Jul 20, 2021, 10:35:47 PMJul 20
to Serge, Erlang Questions
> How do you pass options (2nd argument) to a parse transform?

The options are the compile options.
If you need to pass custom options to the parse transform you can use -D :
-- test_parse.erl
-module(test_parse).
-export([parse_transform/2]).

parse_transform(Forms, Options) ->
io:format("Options: ~p~n", [Options]),
Forms.

-- testt.erl
-module(testt).
-export([test/0]).
-compile({parse_transform, test_parse}).

test() -> hoho.
--
~/work/erlang$ erlc -Dhejhopp -pa . testt.erl
Options: [report_warnings,
{d,hejhopp},
report_errors,
{cwd,"/home/mikael/work/erlang"},
{outdir,"/home/mikael/work/erlang"}]

Serge

unread,
Jul 21, 2021, 1:03:32 AMJul 21
to Mikael Karlsson, Serge, Erlang Questions
Excellent! Thank you very much!
Reply all
Reply to author
Forward
0 new messages