[erlang-questions] Function specs
Joe Armstrong
erlang@REDACTED
Sun Feb 3 18:23:02 CET 2013
You need to parse the source to get this information - example ...
-module(spec).
-compile(export_all).
test() ->
F =
"/Users/joe/nobackup/installed/otp_src_R15B/lib/stdlib/src/lists.erl",
{ok, L} = epp:parse_file(F, "", ""),
[dump(I) || I <- L].
dump({attribute,_,spec,S} = Form) ->
Str = erl_pp:form(Form),
io:format("~s~n",[Str]);
dump(_) ->
void.
When I ran this I got
-spec append(List1, List2) -> List3
when
is_subtype(List1, [T]),
is_subtype(List2, [T]),
is_subtype(List3, [T]),
is_subtype(T, term()).
...
etc.
epp:parse parses the source. erl_pp pretty prints the forms in the parse
tree.
If you take a look at the forms returned by erl_pp you should get the idea
...
Cheers
/Joe
On Sun, Feb 3, 2013 at 5:55 PM, Alessandro Sivieri <
alessandro.sivieri@REDACTED> wrote:
> Hi all,
>
> I was wondering if there is a way to get the function specs (-spec tag)
> from source files (I guess they are not translated into something in the
> compiled files).
> I would like to create an automatic generator of Web forms for an
> application where Erlang modules are installed and their functions executed
> (I'm not boring you with the application details), and it would be nice to
> get the function parameter types "automatically" from the source, provided
> that developers write the correct signature in the tag.
> Maybe a parse transform module could be useful?
>
> --
> Sivieri Alessandro
> alessandro.sivieri@REDACTED
> http://sivieri.wordpress.com/
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20130203/6d5331e2/attachment.htm>
More information about the erlang-questions
mailing list