<div dir="ltr">Hi!<div><br></div><div>I had a simple task: get an AST of a module (.erl) after preprocessing it (includes + parse_transforms).</div><div><br></div><div>I read the docs: <a href="http://erlang.org/doc/man/compile.html">http://erlang.org/doc/man/compile.html</a></div><div>This is how I first understood some options:</div><div>* 'P' — get a transformed code instead of a compiled module</div><div>* 'binary' — get a result in return value instead of a file</div><div><br></div><div>So, I run compile:file("example.erl", ['P', binary]) and indeed get an AST in third position of returned tuple.</div><div>Surprise: example.P file is still written on disk, and it contains Erlang code, not the returned AST.</div><div><br></div><div>Reading the compile.erl I found an undocumented 'to_pp' option.</div><div>Passing 'to_pp' alone also generates example.P file, but this time it contains AST.</div><div>Passing both 'to_pp' and 'binary' works as I wanted — AST in returned tuple, no files written.</div><div><br></div><div>My suggestions:</div><div>* make 'binary' (well, naming legacy) always switch from only writing to file to only returning result.</div><div>* associate every content with its own file extension (e.g. example.ast for AST)</div><div>* document 'to_pp' and other options</div><div><br></div><div>This would make using compiler in non-trivial way easier:</div><div>* choose at which pass should compiler stop</div><div>* choose where the result goes</div><div><br></div><div><br></div><div>Any thoughts on this?</div><div><br></div><div>-- <br><div class="gmail_signature"><div dir="ltr"><div><font face="'courier new', monospace">Danil Zagoskin | <a href="mailto:z@gosk.in" target="_blank">z@gosk.in</a></font></div></div></div></div></div>