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

Max Lapshin <>
Sun Apr 29 09:01:24 CEST 2012

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.


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, _} ->

More information about the erlang-questions mailing list