-module(erlcfg_schema_analyser1).
-include("schema.hrl").
-export([analyse/1]).

analyse([]) ->
    ?DEFAULT_TYPE_MAP;
analyse([Head|Rest]) ->
    Types = ?DEFAULT_TYPE_MAP,
    analyse(Head, Rest, Types).

analyse(Current, [Head|Rest], Types0) ->
    Types1 = eval(Current, Types0),
    analyse(Head, Rest, Types1);

analyse(Current, [], Types0) ->
    Types1 = eval(Current, Types0),
    Types1.

eval(#typedef{name=Name, options=OptionAst}, Types) ->
    Options = cons(OptionAst),
    [{Name, Options}|Types];
eval(_Other, Types) ->
    Types.

cons(#cons{}=Cons) ->
    cons(Cons, []).

cons(#cons{head=Head, tail=nil}, Accm) ->
    lists:reverse([Head|Accm]);
cons(#cons{head=Head, tail=Tail}, Accm) ->
    cons(Tail, [Head|Accm]).


-module(erlcfg_schema_analyser1).
-include("schema.hrl").
-export([analyse/1]).

analyse([]) ->
    ?DEFAULT_TYPE_MAP;
analyse([Head|Rest]) ->
    Types = ?DEFAULT_TYPE_MAP,
    analyse(Head, Rest, Types).

analyse(Current, [Head|Rest], Types0) ->
    Types1 = eval(Current, Types0),
    analyse(Head, Rest, Types1);

analyse(Current, [], Types0) ->
    Types1 = eval(Current, Types0),
    Types1.

eval(#typedef{name=Name, options=OptionAst}, Types) ->
    Options = cons(OptionAst),
    Fun = fun(Val) ->
            lists:member(Val, Options)
    end,
    TypeTest = #type_test{type=Name, test=Fun},
    [{Name, TypeTest}|Types];
eval(_Other, Types) ->
    Types.

cons(#cons{}=Cons) ->
    cons(Cons, []).

cons(#cons{head=Head, tail=nil}, Accm) ->
    lists:reverse([Head|Accm]);
cons(#cons{head=Head, tail=Tail}, Accm) ->
    cons(Tail, [Head|Accm]).


Build a proper validator for type defs
Build a proper validator for type defs

and add that to the validator mapping structure

Signed-off-by: Essien Ita Essien <bd402154b008803b915ff3326ddb7528f7e13a6b@gmail.com>
