anchor.diff:      end.
   
   %% @private
  -check_mandatory(#parse{mandatory=Mandatory, syntax=Syntax}=Parse) ->
  +check_mandatory(#parse{syntax = Syntax} = Parse) ->
       SynMand = maps:get('__mandatory', Syntax, []),
  -    check_mandatory(Mandatory++SynMand, Parse).
  +    check_mandatory(SynMand, Parse).
   
   
   %% @private
   check_mandatory([], _Parse) ->
       ok;
   
  -check_mandatory([Term|Rest], #parse{ok_exp=Exp}=Parse) ->
  -    case lists:keymember(to_bin(Term), 1, Exp) of
  +check_mandatory([Key | Rest], #parse{ok = Ok} = Parse) ->
  +    case lists:keymember(Key, 1, Ok) of
           true ->
               check_mandatory(Rest, Parse);
           false ->
  -            %% Path should be already present at Term, right?
  -            %%  {error, {missing_field, path_key(Term, Parse)}}
  -            {error, {missing_field, to_bin(Term)}}
  +            {error, {missing_field, path_key(Key, Parse)}}
       end.
  -
   
   
   %% @private
  
positive.code:             {error, Error}
      end;
  
  do_parse([Key|Rest], Parse) ->
      do_parse([{Key, true}|Rest], Parse).
  
  
  %% @private
  do_parse_key(Key, Val, Parse) ->
      case to_existing_atom(Key) of
          {ok, Key2} ->
              case find_config(Key2, Val, Parse) of
                  {ok, Key3, Val3, Parse2} ->
                      PathKey = path_key(Key3, Parse2),
                      #parse{ok=OK, ok_exp=OkExp, opts=Opts} = Parse2,
                      Key4 = case maps:get({binary_key, PathKey}, Opts, false) of
                          false -> Key3;
                          true -> to_bin(Key3)
                      end,
                      #parse{ok=OK, ok_exp=OkExp} = Parse2,
                      Parse3 = Parse2#parse{
                          ok = [{Key4, Val3}|OK],
                          ok_exp = [{PathKey, Val3}|OkExp]
                      },
                      {ok, Parse3};
                  {nested, Val2, Nested} ->
                      #parse{defaults=Defaults, opts=Opts} = Parse,
                      NestedParse = Parse#parse{
                          ok = [], 
                          path = path_key(Key, Parse), 
                          syntax = Nested,
                          defaults = maps:get(Key2, Defaults, #{})
                      },
                      case do_parse(Val2, NestedParse) of
                          {ok, #parse{ok=OK2, ok_exp=Exp2, no_ok=NoOK2}} ->
                              PathKey = path_key(Key2, Parse),
                              Key3 = case maps:get({binary_key, PathKey}, Opts, false) of
                                  false -> Key2;
                                  true -> to_bin(Key2)
                              end,
                              #parse{ok=OK} = Parse,
                              Parse2 = Parse#parse{
                                  ok = [{Key3, {OK2}}|OK],
                                  ok_exp = Exp2,
                                  no_ok = NoOK2
                              },
                              {ok, Parse2};
                          {error, Error} ->
                              {error, Error}
                      end;
                  no_spec ->
                      #parse{no_ok=NoOk} = Parse,
                      {ok, Parse#parse{no_ok=[path_key(Key, Parse)|NoOk]}};
                  ignore ->
                      {ok, Parse};
                  {error, Error} ->
                      {error, Error}
              end;
          error ->
              #parse{no_ok=NoOk} = Parse,
              {ok, Parse#parse{no_ok=[path_key(Key, Parse)|NoOk]}}
      end.
  
  
  %% @private
  find_config(Key, Val, #parse{syntax=Syntax}=Parse) ->
      case maps:get(Key, Syntax, not_found) of
          not_found ->
              no_spec;
          Fun when is_function(Fun) ->
              FunRes = if
                  is_function(Fun, 1) ->
                      catch Fun(Val);
                  is_function(Fun, 2) ->
                      catch Fun(Key, Val);
                  is_function(Fun, 3) -> 
                      #parse{ok=Ok, ok_exp=Exp, no_ok=NoOk, opts=Opts} = Parse,
                      FunOpts = Opts#{ok=>Ok, ok_exp=>Exp, no_ok=>NoOk},
                      catch Fun(Key, Val, FunOpts)
              end,
              case FunRes of
                  ok ->
                      {ok, Key, Val, Parse};
                  {ok, Val2} ->
                      {ok, Key, Val2, Parse};
                  {ok, Key2, Val2} when is_atom(Key2) ->
                      {ok, Key2, Val2, Parse};
                  % {new_ok, OKB} ->
                  %     parse(Rest, OKB, NoOk, Syntax, Opts);
                  error ->
                      {error, syntax_error(Key, Parse)};
                  {error, Error} ->
                      {error, Error};
                  {'EXIT', Error} ->
                      lager:warning("NkLIB Syntax: error calling syntax fun for "
                                    "(~p, ~p) ~p", [Key, Val, Error]),
                      error(fun_call_error)
              end;
          Nested when is_map(Nested) ->
              case Val of
                  _ when is_map(Val) ->
                      {nested, maps:to_list(Val), Nested};
                  {List} when is_list(List) ->
                      {nested, List, Nested};
                  _ ->
                      {error, syntax_error(Key, Parse)}
              end;
          ignore ->
              ignore;
          SyntaxOp ->
              case spec(SyntaxOp, Key, Val, Parse) of
                  {ok, Val2} ->
                      {ok, Key, Val2, Parse};
                  {ok, Val2, Parse2} ->
                      {ok, Key, Val2, Parse2};
                  error ->
                      {error, syntax_error(Key, Parse)};
                  {error, Error} ->
                      {error, Error};
                  unknown ->
                      error({invalid_syntax, SyntaxOp})
              end
      end.
  
  
  
  %% @private
  -spec spec(syntax_opt(), term(), term(), #parse{}) ->
      {ok, term()} | {ok, term(), #parse{}} |
      error | {error, term()} | unknown.
  
  spec({ListType, SyntaxOp}, Key, Val, Parse) when ListType==list; ListType==slist; ListType==ulist ->
      case Val of
          [] ->
              {ok, []};
          [Head|_] when not is_integer(Head) ->
              do_parse_list(ListType, SyntaxOp, Key, Val, Parse, []);
          _ ->
              do_parse_list(ListType, SyntaxOp, Key, [Val], Parse, [])
      end;
  
  spec({syntax, Syntax}, Key, Val, Parse) ->
      Path2 = path_key(Key, Parse),
      Syntax2 = case Syntax of
          #{'__mandatory':=List} ->
              List2 = [<<Path2/binary, $., (to_bin(M))/binary>> || M <- List],
              Syntax#{'__mandatory':=List2};
          _ ->
              Syntax
      end,
      case parse(Val, Syntax2, #{path=>Path2}) of
          {ok, Parsed, Exp2, NoOk2} ->
              %% lager:warning("Parsed: ~p\nExp: ~p\nNoOk: ~p", [Parsed, Exp, NoOk]),
              #parse{ok_exp=Exp, no_ok=NoOk} = Parse,
              Parse2 = Parse#parse{ok_exp=Exp2++Exp, no_ok=NoOk2++NoOk},
              {ok, Parsed, Parse2};
          {error, Error} ->
              {error, Error}
      end;
  
  spec([Opt|Rest], Key, Val, Parse) ->
      case spec(Opt, Key, Val, Parse) of
          {ok, Val2} ->
              {ok, Val2};
          {ok, Val2, Parse2} ->
              {ok, Val2, Parse2};
          _ ->
              spec(Rest, Key, Val, Parse)
      end;
  
  spec([], _Key, _Val, _Parse) ->
      error;
  
  spec(SyntaxOp, _Key, Val, _Parse) ->
      spec(SyntaxOp, Val).
  
  
  
  %% @private
  -spec spec(syntax_opt(), term()) ->
      {ok, term()} | error | {error, term()} | unknown.
  
  spec(any, Val) ->
      {ok, Val};
  
negative.code: 
  
  %% @private
  path_key(Key, #parse{path = Path}) ->
      case Path of
          <<>> ->
              to_bin(Key);
  