diff options
| author | Théo Zimmermann | 2020-04-07 10:42:29 +0200 |
|---|---|---|
| committer | Théo Zimmermann | 2020-04-20 15:52:01 +0200 |
| commit | 9de39626d925aa8ed0138fc5b90ee30ccf1ac4c1 (patch) | |
| tree | 904fcae80ca31bbe9ebc33478521747f7b9d6847 /vernac | |
| parent | 078e6c6d27bc3a13bb9e7ac6c9c5b8e05450af80 (diff) | |
Improve undeclared key messages.
Diffstat (limited to 'vernac')
| -rw-r--r-- | vernac/vernacentries.ml | 42 |
1 files changed, 25 insertions, 17 deletions
diff --git a/vernac/vernacentries.ml b/vernac/vernacentries.ml index 044e479aeb..a6a38e5253 100644 --- a/vernac/vernacentries.ml +++ b/vernac/vernacentries.ml @@ -1554,26 +1554,34 @@ let vernac_set_option ~locality table v = match v with vernac_set_option0 ~locality table v | _ -> vernac_set_option0 ~locality table v -let vernac_add_option key lv = - let f = function - | StringRefValue s -> (get_string_table key).add (Global.env()) s - | QualidRefValue locqid -> (get_ref_table key).add (Global.env()) locqid +(* We have to request twice the same polymorphic function as argument + because OCaml won't compute the same type for it in both cases. *) +let iter_table ~f ~g key lv = + let aux = function + | StringRefValue s -> + begin + try f (get_string_table key) (Global.env()) s + with Not_found -> error_no_table_of_this_type ~kind:"string" key + end + | QualidRefValue locqid -> + begin + try g (get_ref_table key) (Global.env()) locqid + with Not_found -> error_no_table_of_this_type ~kind:"qualid" key + end in - try List.iter f lv with Not_found -> error_undeclared_key key + List.iter aux lv -let vernac_remove_option key lv = - let f = function - | StringRefValue s -> (get_string_table key).remove (Global.env()) s - | QualidRefValue locqid -> (get_ref_table key).remove (Global.env()) locqid - in - try List.iter f lv with Not_found -> error_undeclared_key key +let vernac_add_option = + let aux table = table.add in + iter_table ~f:aux ~g:aux -let vernac_mem_option key lv = - let f = function - | StringRefValue s -> (get_string_table key).mem (Global.env()) s - | QualidRefValue locqid -> (get_ref_table key).mem (Global.env()) locqid - in - try List.iter f lv with Not_found -> error_undeclared_key key +let vernac_remove_option = + let aux table = table.remove in + iter_table ~f:aux ~g:aux + +let vernac_mem_option = + let aux table = table.mem in + iter_table ~f:aux ~g:aux let vernac_print_option key = try (get_ref_table key).print () |
