Skip to content

Instantly share code, notes, and snippets.

@maxlapshin
Created April 29, 2012 06:59
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save maxlapshin/2537756 to your computer and use it in GitHub Desktop.
Save maxlapshin/2537756 to your computer and use it in GitHub Desktop.
Parse erlang config file loaded into binary
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment