public
Created

Parse erlang config file loaded into binary

  • Download Gist
parse_erlang.erl
Erlang
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
parse(Text) when is_binary(Text) ->
parse(binary_to_list(Text));
 
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.

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.