epp:parse_file 的 Erlang 模块语法树未满,erl_parse:parse_form 给出错误

Erlang module's syntax tree with epp:parse_file is not full and erl_parse:parse_form gives an error

我正在尝试构建脚本以从源文件中提取一些 erlang 代码,但我的方法不起作用。 这是我尝试过的:

{ok, Forms} = epp:parse_file("src/day_tasks.erl", [{includes, "include"}]), 
file:write_file("/projects/result.txt",
io_lib:format("~p", [Forms])).

这种方法有效,AST 已构建,但输出中缺少某些函数。不过,它们的属性已经到位。我在构建的语法树中看到了很多像这样的元组,而不是它们:

{error,{10,epp,{include,file,"cards.hrl"}}},
{error,{320,epp,{undefined,'LONG_TASK',none}}}

而且我知道它在哪里包含属性,在哪里是在模块中定义并在函数体中使用的宏。但我不知道我能做些什么。

我尝试了另一种方法来获取树,它看起来像这样:

{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])).

但是 erl_parse:parse_form(Tokens) 失败并出现错误:

** exception error: no match of right hand side value {error,{6,erl_parse,["syntax error before: ","'-'"]}}

第6行是

-compile(export_all).

模块属性位于模块名称属性之后。 所以我在这里,我被困住了,不知道我还能做什么。

为模块获取完全构建的语法树的正确方法是什么?

epp:parse_file("src/day_tasks.erl", [{includes, "include"}]),

includes 元组的第二个元素定义为 IncludePath 类型,它是一个列表:

Options = 
    [{includes, IncludePath :: [DirectoryName :: file:name()]} |
    ...

file:名称() = 字符串() |原子() | deep_list()