construct Name ENUMERATED Enum io_lib format cre_ Name Offs length lis

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
construct(Name, {'ENUMERATED', Enum}, []) ->
H = io_lib:format("cre_~s(V) ->\n", [Name]),
Offs = length(lists:flatten(H)),
Fun = fun({'NamedNumber', Atom, Num}, A) ->
A ++ io_lib:format("~n~s~b -> ~s;",
[lists:duplicate(8, $ ), Num, Atom]);
('EXTENSIONMARK', A) -> A;
(Other, A) ->
io:format(" *** ENUMERATED: Unhandled: ~p ***~n", [Other]),
A
end,
D = H
++ " case V of"
++ lists:foldl(Fun, "", Enum)
++ io_lib:format("\n _ -> throw({'~s', badarg})\n", [Name])
++ " end.\n\n",
lists:flatten(D);