%% -*- mode: erlang; indent-tabs-mode: nil -*-

Conf0 = CONFIG,
MapString = "#{X => 1}.",
HasOpt = {d,'HAS_MAPS',true},
FullOpt = {d,'HAS_FULL_KEYS',true},

MapsOpts = case erl_scan:string(MapString) of
              {ok,Ts,_} ->
                  case erl_parse:parse_exprs(Ts) of
                      {ok,Es} ->                %We have maps!
                          Binds = [{'X',49}],   %We need to bind X
                          case erl_lint:exprs(Es, Binds) of
                              {ok,_} -> [HasOpt,FullOpt];
                           {error,_,_} -> [HasOpt]
                       end;
                   {error,_} -> []
               end;
           {error,_,_} -> []
       end,

case lists:keyfind(erl_opts, 1, Conf0) of
    {erl_opts,Opts} ->                          %Existing erl_opts
        NewOpts = {erl_opts,Opts ++ MapsOpts},
        lists:keyreplace(erl_opts, 1, Conf0, NewOpts);
    false ->                                    %No erl_opts
        Conf0 ++ [{erl_opts,MapsOpts}]
end.
