Commits

Markus Mottl committed ce5db6f

Final API and documentation cleanups for record field defaults

Comments (0)

Files changed (3)

base/sexplib/syntax/pa_sexp_conv.ml

       Loc.raise loc (Failure "sexp record field handler defined twice")
 
   let () =
-    Pa_type_conv.add_record_generator "sexp_drop_default" (fun loc ->
+    Pa_type_conv.add_record_field_generator "sexp_drop_default" (fun loc ->
       check_record_field_handler loc;
       Hashtbl.replace record_field_handlers ~key:loc ~data:`drop_default)
 
   let () =
-    Pa_type_conv.add_record_generator_with_arg "sexp_drop_if"
+    Pa_type_conv.add_record_field_generator_with_arg "sexp_drop_if"
       Syntax.expr (fun expr_opt loc ->
         check_record_field_handler loc;
         let test =

base/type_conv/syntax/pa_type_conv.ml

 let sig_exn_generators = Hashtbl.create 0
 
 (* Map of "with"-generators for record fields *)
-type record_generator = Loc.t -> unit
+type record_field_generator = Loc.t -> unit
 
-let record_generators = Hashtbl.create 0
+let record_field_generators = Hashtbl.create 0
 
 (* Check that there is no argument for generators that do not expect any *)
 let no_arg id e arg typ =
   Hashtbl.remove gens id
 
 (* Register a "with"-generator for record fields *)
-let add_record_generator_with_arg id entry e =
-  safe_add_gen record_generators id entry e
+let add_record_field_generator_with_arg id entry e =
+  safe_add_gen record_field_generators id entry e
 
-let add_record_generator id e =
-  add_record_generator_with_arg id ignore_tokens (no_arg id e)
+let add_record_field_generator id e =
+  add_record_field_generator_with_arg id ignore_tokens (no_arg id e)
 
 (* Remove a "with"-generator for record fields *)
-let rm_record_generator id = Hashtbl.remove record_generators id
+let rm_record_field_generator id = Hashtbl.remove record_field_generators id
 
 
 (* General purpose code generation module *)
   let coll drv der_sis = <:sig_item< $der_sis$; $sig_exn_generate tp drv$ >> in
   List.fold_right coll drvs (SgNil _loc)
 
-let remember_record_generators el drvs =
+let remember_record_field_generators el drvs =
   let act drv =
-    let gen = find_generator ~name:"record field" record_generators in
+    let gen = find_generator ~name:"record field" record_field_generators in
     gen el drv
   in
   List.iter act drvs
     [[
       name = a_LIDENT; ":"; tp = poly_type;
       "with"; drvs = LIST1 generator SEP "," ->
-        remember_record_generators _loc drvs;
+        remember_record_field_generators _loc drvs;
         <:ctyp< $lid:name$ : $tp$ >>
     | "mutable"; name = a_LIDENT; ":"; tp = poly_type;
       "with"; drvs = LIST1 generator SEP "," ->
-        remember_record_generators _loc drvs;
+        remember_record_field_generators _loc drvs;
         <:ctyp< $lid:name$ : mutable $tp$ >>
     ]];
 END
 
 (* Add "default" to set of record field generators *)
 let () =
-  add_record_generator_with_arg "default" Syntax.expr
+  add_record_field_generator_with_arg "default" Syntax.expr
     (fun expr_opt loc ->
       let default =
         match expr_opt with
         | Some expr -> expr
-        | None -> Loc.raise loc (Failure "could not parse expression")
+        | None -> Loc.raise loc (Failure "could not parse default expression")
       in
       Hashtbl.replace Gen.record_defaults loc default)

base/type_conv/syntax/pa_type_conv.mli

     @param is_exn = [false]
 *)
 
-(** Type of record code generators *)
-type record_generator = Loc.t -> unit
+(** Type of record field code generators *)
+type record_field_generator = Loc.t -> unit
 
-val add_record_generator : string -> record_generator -> unit
-(** [add_record_generator gen_name gen] adds the record field code generator
-    [gen_name], which acts on a record field location [loc], a record field
-    [name], and the record field type [tp]. *)
+val add_record_field_generator : string -> record_field_generator -> unit
+(** [add_record_field_generator gen_name gen] adds the record field code
+    generator [gen] with name [gen_name], which acts on the location
+    identifiying the record field. *)
 
-val add_record_generator_with_arg :
+val add_record_field_generator_with_arg :
   string -> 'a Camlp4.PreCast.Gram.Entry.t ->
-  ('a option -> record_generator) -> unit
-(** [add_record_generator_with_arg name entry generator] same as
-    [add_record_generator], but the generator may accept an argument, which
-    is parsed with [entry]. *)
+  ('a option -> record_field_generator) -> unit
+(** [add_record_field_generator_with_arg name entry generator] same as
+    [add_record_field_generator], but the [generator] takes an argument,
+    which is parsed with [entry].  If [None] is passed to the generator,
+    parsing of the argument failed, otherwise [Some arg] will be passed,
+    where [arg] is the successfully parsed argument. *)
 
-val rm_record_generator : string -> unit
-(** [rm_record_generator name] removes the record field code generator named
-    [name]. *)
+val rm_record_field_generator : string -> unit
+(** [rm_record_field_generator name] removes the record field code generator
+    named [name]. *)
 
 
 (** {6 Utility functions} *)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.