Permalink
Browse files

Modify service generator

* Merge different enum values into the same module for parameters
  with the same name
* Add documentation to enum values
  • Loading branch information...
1 parent 03413ae commit 95ccd771af461a323d5b4913c45a11ec99b37e1f @astrada committed Mar 16, 2013
Showing with 194 additions and 152 deletions.
  1. +45 −4 tools/serviceGenerator.ml
  2. +149 −148 tools/serviceGeneratorState.ml
@@ -500,12 +500,52 @@ struct
let compare (id1, _) (id2, _) = compare id1 id2
end)
+ let merge element s =
+ if mem element s then
+ let (_, { Field.field_type; _ }) = element in
+ if ComplexType.is_enum field_type then begin
+ let scalar =
+ match field_type.ComplexType.data_type with
+ ComplexType.Scalar s -> s
+ | _ -> assert false in
+ let enum = scalar.ScalarType.enum in
+ let enum_descriptions = scalar.ScalarType.enumDescriptions in
+ let old_element =
+ filter (fun (id, _) -> id = fst element) s |> choose in
+ let (_, { Field.field_type; _ }) = old_element in
+ let old_scalar =
+ match field_type.ComplexType.data_type with
+ ComplexType.Scalar s -> s
+ | _ -> assert false in
+ let old_enum = old_scalar.ScalarType.enum in
+ let old_enum_descriptions = old_scalar.ScalarType.enumDescriptions in
+ let (new_enum, new_enum_descriptions) =
+ List.fold_left2
+ (fun ((es, ds) as r) e d ->
+ if List.mem e es then r
+ else (e :: es, d :: ds))
+ ([], [])
+ (old_enum @ enum)
+ (old_enum_descriptions @ enum_descriptions) in
+ let new_scalar = scalar
+ |> ScalarType.enum ^= List.rev new_enum
+ |> ScalarType.enumDescriptions ^= List.rev new_enum_descriptions in
+ let new_element = element
+ |> GapiLens.second
+ ^%= Field.field_type
+ ^%= ComplexType.data_type ^= ComplexType.Scalar new_scalar in
+ remove element s |> add new_element
+ end else s
+ else
+ add element s
+
let add_parameters_list xs s =
List.fold_left
(fun s' (id, parameter) ->
let complex_type = ComplexType.create id parameter in
let field = Field.create (id, complex_type) in
- add (id, field) s')
+ let element = (id, field) in
+ merge element s')
s
xs
@@ -1239,10 +1279,11 @@ let rec generate_service_module_signature
"@\nmodule %s :@\n@[<v 2>sig@,@[<v 2>type t =@,| Default@,"
enum_module.EnumModule.ocaml_name;
List.iter
- (fun (_, { EnumModule.constructor; _ }) ->
+ (fun (_, { EnumModule.constructor; EnumModule.description; _ }) ->
Format.fprintf formatter
- "| %s@,"
- constructor)
+ "| %s (** %s *)@,"
+ constructor
+ description)
enum_module.EnumModule.values;
Format.fprintf formatter "@]@,val to_string : t -> string@,@,val of_string : string -> t@,@]@\nend@\n";
in
Oops, something went wrong.

0 comments on commit 95ccd77

Please sign in to comment.