[erlang-questions] compile options+documentation consistency
Danil Zagoskin
z@REDACTED
Wed Jun 6 12:16:53 CEST 2018
Hi!
I had a simple task: get an AST of a module (.erl) after preprocessing it
(includes + parse_transforms).
I read the docs: http://erlang.org/doc/man/compile.html
This is how I first understood some options:
* 'P' — get a transformed code instead of a compiled module
* 'binary' — get a result in return value instead of a file
So, I run compile:file("example.erl", ['P', binary]) and indeed get an AST
in third position of returned tuple.
Surprise: example.P file is still written on disk, and it contains Erlang
code, not the returned AST.
Reading the compile.erl I found an undocumented 'to_pp' option.
Passing 'to_pp' alone also generates example.P file, but this time it
contains AST.
Passing both 'to_pp' and 'binary' works as I wanted — AST in returned
tuple, no files written.
My suggestions:
* make 'binary' (well, naming legacy) always switch from only writing to
file to only returning result.
* associate every content with its own file extension (e.g. example.ast for
AST)
* document 'to_pp' and other options
This would make using compiler in non-trivial way easier:
* choose at which pass should compiler stop
* choose where the result goes
Any thoughts on this?
--
Danil Zagoskin | z@REDACTED
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20180606/420c1421/attachment.htm>
More information about the erlang-questions
mailing list