type shape_field_struct = {
sf_i : int;
sf_name : string;
- sf_fields : PP.field list;
+ sf_fields : (string * PP.f_type) list;
}
and content_field_struct = {
cf_i : int;
cf_name : string;
- cf_fields : PP.field list;
+ cf_fields : (string * PP.f_type) list;
}
and parser_ = {
(* Minimization of shape fields & content fields. *)
-let cmp { PP.field_name = n1 } { PP.field_name = n2 } = compare n1 n2
+let cmp (n1,_) (n2,_) = compare n1 n2
let hash_values h = Hashtbl.fold (fun _ v vs -> v :: vs) h []
let rh = Hashtbl.create 13 in
let only_shape_fields =
- List.filter (
- fun { PP.field_type = typ } ->
- classify_field names typ = ShapeField
+ List.filter_map (
+ fun { PP.field_name = name; field_type = typ } ->
+ if classify_field names typ = ShapeField then Some (name, typ)
+ else None
)
in
{ PP.struct_fields = fields; struct_name = name_check }) ->
assert (struct_name = name_check);
let fields = List.sort ~cmp (only_shape_fields fields) in
- let key = List.map (fun { PP.field_name = name } -> name) fields in
+ let key = List.map fst fields in
let sf =
try Hashtbl.find h key
with Not_found ->
let rh = Hashtbl.create 13 in
let only_content_fields =
- List.filter (
- fun { PP.field_type = typ } ->
- classify_field names typ = ContentField
+ List.filter_map (
+ fun { PP.field_name = name; field_type = typ } ->
+ if classify_field names typ = ContentField then Some (name, typ)
+ else None
)
in
{ PP.struct_fields = fields; struct_name = name_check }) ->
assert (struct_name = name_check);
let fields = List.sort ~cmp (only_content_fields fields) in
- let key = List.map (fun { PP.field_name = name } -> name) fields in
+ let key = List.map fst fields in
let cf =
try Hashtbl.find h key
with Not_found ->