Browse files

protobuffs_compile: simplified generate_field_definitions().

  • Loading branch information...
1 parent 5920e1f commit d073e8a1606880f69e8904a872fe5ae31ccd202c @eriksoe eriksoe committed Jul 4, 2011
Showing with 7 additions and 12 deletions.
  1. +7 −12 src/protobuffs_compile.erl
View
19 src/protobuffs_compile.erl
@@ -502,20 +502,15 @@ write_header_include_file(Basename, Messages) ->
%% @hidden
generate_field_definitions(Fields) ->
- generate_field_definitions(Fields, []).
+ [lists:flatten(generate_field_definition(Field)) || Field <- Fields].
%% @hidden
-generate_field_definitions([], Acc) ->
- lists:reverse(Acc);
-generate_field_definitions([{Name, required, _} | Tail], Acc) ->
- Head = lists:flatten(io_lib:format("~s = erlang:error({required, ~s})", [Name, Name])),
- generate_field_definitions(Tail, [Head | Acc]);
-generate_field_definitions([{Name, _, none} | Tail], Acc) ->
- Head = lists:flatten(io_lib:format("~s", [Name])),
- generate_field_definitions(Tail, [Head | Acc]);
-generate_field_definitions([{Name, optional, Default} | Tail], Acc) ->
- Head = lists:flatten(io_lib:format("~s = ~p", [Name, Default])),
- generate_field_definitions(Tail, [Head | Acc]).
+generate_field_definition({Name, required, _}) ->
+ io_lib:format("~s = erlang:error({required, ~s})", [Name, Name]);
+generate_field_definition({Name, _, none}) ->
+ io_lib:format("~s", [Name]);
+generate_field_definition({Name, optional, Default}) ->
+ io_lib:format("~s = ~p", [Name, Default]).
%% @hidden
atomize(String) ->

0 comments on commit d073e8a

Please sign in to comment.