Generating type specs programmatically

Hello forum,

I’ve been working on a code-generating tool, leveraging erl_syntax to build an AST containing arbitrary Erlang functions; I then use erl_pp to generate the corresponding Erlang code and write the result onto a source code file.

All is well so far, but now I want to generate type specs and function specs with which to annotate the generated code - and I can’t for the life of me figure out how to do it within erl_syntax.

All of the different attempts I’ve made end up either crashing within erl_syntax or erl_pp, or at best result in INVALID-FORM literals within the generated code.

Would any of you be able to point me in the right direction?

Thanks in advance!

For future reference, someone at the erlang-questions mailing list pointed me to this document that describes all the desired constructs; it just happens that there is no API, for some of them, within erl_syntax.

1 Like