aboutsummaryrefslogtreecommitdiff
path: root/engine/namegen.ml
diff options
context:
space:
mode:
authorThéo Zimmermann2020-04-01 16:54:37 +0200
committerThéo Zimmermann2020-04-06 15:30:08 +0200
commit5c5fbf68034fdd18ddfcd19c9c8b1438af6b5c92 (patch)
tree32313fbf73082cff3da3832b0ff709c192ec28b7 /engine/namegen.ml
parent2089207415565e8a28816f53b61d9292d04f4c59 (diff)
Clean and fix definitions of options.
- Provide new helper functions in `Goptions` on the model of `declare_bool_option_and_ref`; - Use these helper functions in many parts of the code base (encapsulates the corresponding references); - Move almost all options from `declare_string_option` to `declare_stringopt_option` (only "Warnings" continue to use the former). This means that these options now support `Unset` to get back to the default setting. Note that there is a naming misalignment since `declare_int_option` is similar to `declare_stringopt_option` and supports `Unset`. When "Warning" is eventually migrated to support `Unset` as well, we can remove `declare_string_option` and rename `declare_stringopt_option` to `declare_string_option`. - For some vernac options and flags that have an equivalent command-line option or flag, implement it like the standard `-set` and `-unset`.
Diffstat (limited to 'engine/namegen.ml')
-rw-r--r--engine/namegen.ml32
1 files changed, 16 insertions, 16 deletions
diff --git a/engine/namegen.ml b/engine/namegen.ml
index 370f35f6ed..c4472050f8 100644
--- a/engine/namegen.ml
+++ b/engine/namegen.ml
@@ -219,22 +219,22 @@ let get_mangle_names =
~key:["Mangle";"Names"]
~value:false
-let mangle_names_prefix = ref (Id.of_string "_0")
-
-let set_prefix x = mangle_names_prefix := forget_subscript x
-
-let () = Goptions.(
- declare_string_option
- { optdepr = false;
- optkey = ["Mangle";"Names";"Prefix"];
- optread = (fun () -> Id.to_string !mangle_names_prefix);
- optwrite = begin fun x ->
- set_prefix
- (try Id.of_string x
- with CErrors.UserError _ -> CErrors.user_err Pp.(str ("Not a valid identifier: \"" ^ x ^ "\".")))
- end })
-
-let mangle_id id = if get_mangle_names () then !mangle_names_prefix else id
+let mangle_names_prefix =
+ Goptions.declare_interpreted_string_option_and_ref
+ ~depr:false
+ ~key:["Mangle";"Names";"Prefix"]
+ ~value:(Id.of_string "_0")
+ (fun x ->
+ (try
+ Id.of_string x
+ with
+ | CErrors.UserError _ ->
+ CErrors.user_err Pp.(str ("Not a valid identifier: \"" ^ x ^ "\"."))
+ ) |> forget_subscript
+ )
+ (fun x -> Id.to_string x)
+
+let mangle_id id = if get_mangle_names () then mangle_names_prefix () else id
(* Looks for next "good" name by lifting subscript *)