parse external files -- SOLVED
Gaspar Chilingarov
nm@REDACTED
Fri Oct 28 11:44:13 CEST 2005
>> On 27 Oct 2005, at 23:25, Gaspar Chilingarov wrote:
>> Hi all!
>>
>> I need to have files in plaintext format, describing some forms
>> functionality -
>> which i need to load, parse and generate html from them.
>>
>> files will look like this:
>>
>> {form, personalinfo,
>> [ {firstname, string},
>> {lastname, string},
>> {submit, button}
>> ],
>> fun
>> (List) -> validateForm(List)
>> end
>> }
>>
>>
>> so, I need them parse info valid erlkang terms - tuples, lists, funs,
>> etc.
>> I understand , that such functionality already is in library :) but ,
>> hm, I've
>> missed where )
> Sean Hinde wrote:
> (dcr@REDACTED)25> {ok, B, _}=erl_scan:string(A).
> {ok,[{'{',1},
> {atom,1,form},
> {',',1},
> {atom,1,personalinfo},
> {',',1},
> {'[',2},
> etc...
>
> (dcr@REDACTED)28> erl_parse:parse_exprs(B ++ [{dot,1}]).
> {ok,[{tuple,1,
> [{atom,1,form},
> {atom,1,personalinfo},
> {cons,2,
> {tuple,2,[{atom,2,firstname},{atom,2,string}]},
> {cons,3,
> {tuple,3,[{atom,3,lastname},{atom,3,string}]},
> {cons,4,{tuple,4,[{atom,4|...},{atom|...}]},
> {nil,5}}}},
> {'fun',6,
> {clauses,[{clause,7,
> [{var,7,'List'}],
> [],
> [{call,7,{atom|...}, [...]}]}]}}]}]}
>
I should do one more step -- just call
erl_eval:exprs/2 on result, returned from erl_parse:parse_exprs
so whole code shoudl look like this -
toErlangStructure(Text) ->
{ok, Tokens, _} = erl_scan:string(Text),
{ok, ParsedForm} = erl_parse:parse_exprs(Tokens),
Bindings = erl_eval:new_bindings(),
{value, ErlangTerms, _NewBinding} = erl_eval:exprs(ParsedForm,
Bindings),
ErlangTerms.
some binding processign should be done, of course, but in general that's
it :)
thanks all for replies.
--
Gaspar Chilingarov
System Administrator
t +37491 419763 (mob)
t +37410 240399 (office)
w www.web.am
i 63174784
e nm@REDACTED
More information about the erlang-questions
mailing list