[erlang-questions] Specs

Kostis Sagonas kostis@REDACTED
Tue Jun 7 22:40:46 CEST 2011


James Churchman wrote:
> Hi guys
> 
> When you parse a file with the epp module it has no problems with specs
> 
> However when using erl_scan then passing on to erl_parse, in order to parse a string not a file, it fails on -specs in the code
> 
> Is there a spec aware version of the erl_parse module ?

I find this question a bit strange... the erl_parse module *is* spec 
aware. This is actually how specs are parsed in the system.

Does the following do what you want?

42> SpecInString = "-spec my_function(some_type()) -> 42 | 'gazonk'.",
42> {ok, Toks, 1} = erl_scan:string(SpecInString),
42> erl_parse:parse_form(Toks).
{ok,{attribute,1,spec,
                {{my_function,1},
                 [{type,1,'fun',
                        [{type,1,product,[{type,1,some_type,[]}]},
 
{type,1,union,[{integer,1,42},{atom,1,gazonk}]}]}]}}}

Kostis



More information about the erlang-questions mailing list