[erlang-questions] Quick snippet: how to parse erlang config file, loaded into memory

25 views
Skip to first unread message

Max Lapshin

unread,
Apr 29, 2012, 3:01:24 AM4/29/12
to Erlang-Questions Questions
There is a very convenient tool file:path_consult for config files.
But what if config is loaded into memory? You have to dig into sources.


https://gist.github.com/2537756

parse(Text) when is_list(Text) ->
parse(Text, [], 0, []).

parse(Text, Env, Line, Acc) ->
case erl_scan:tokens([], Text, Line) of
{done, {ok, Scanned, NewLine}, Rest} ->
{ok, Parsed} = erl_parse:parse_exprs(Scanned),
{value, Out, NewEnv} = erl_eval:exprs(Parsed, Env),
parse(Rest, NewEnv, NewLine, [Out|Acc]);
{more, _} ->
lists:reverse(Acc)
end.
_______________________________________________
erlang-questions mailing list
erlang-q...@erlang.org
http://erlang.org/mailman/listinfo/erlang-questions
Reply all
Reply to author
Forward
0 new messages