I'm trying to build a script to extract some pieces of the erlang code from the source files, but my approaches don't work.
Here is what I tried:
{ok, Forms} = epp:parse_file("src/day_tasks.erl", [{includes, "include"}]),
file:write_file("/projects/result.txt",
io_lib:format("~p", [Forms])).
This kind of worked, the AST was built, but some functions are missing in the output. The attributes for them are in place though. Instead of them I see a lot of tuples like this inside of the built syntax tree:
{error,{10,epp,{include,file,"cards.hrl"}}},
{error,{320,epp,{undefined,'LONG_TASK',none}}}
And I know that it where include attribute and where is a macro defined in the module and used in the function's body. What I don't know though is what can I do about it.
I tried another approach to get the tree, it looks like this:
{ok, Data} = file:read_file("src/day_tasks.erl"),
{ok, Tokens, _Lines} = erl_scan:string(binary_to_list(Data)),
{ok, Abs} = erl_parse:parse_form(Tokens),
file:write_file("/projects/result1.txt", io_lib:format("~p", [Abs])).
But erl_parse:parse_form(Tokens) fails with the error:
** exception error: no match of right hand side value {error,{6,erl_parse,["syntax error before: ","'-'"]}}
The 6-th line is the line where the
-compile(export_all).
module attribute resides, right after module name attribute.
So here I am, I'm stuck and don't know what else can I do.
What is the right way to get fully built syntax tree for the module?
question from:
https://stackoverflow.com/questions/65852473/erlang-modules-syntax-tree-with-eppparse-file-is-not-full-and-erl-parseparse