Debian Codegraph @

interp/notation.mli

raw symbols SCIP
1 (************************************************************************)
2 (* * The Rocq Prover / The Rocq Development Team *)
3 (* v * Copyright INRIA, CNRS and contributors *)
4 (* <O___,, * (see version control and CREDITS file for authors & dates) *)
5 (* \VV/ **************************************************************)
6 (* // * This file is distributed under the terms of the *)
7 (* * GNU Lesser General Public License Version 2.1 *)
8 (* * (see LICENSE file for the text of the license) *)
9 (************************************************************************)
10
11 open Names
12 open Libnames
13 open Constrexpr
14 open Glob_term
15 open Notation_term
16 open Notationextern
17 open Globnames
18
19 (** Notations *)
20
21 val notation_cat : Libobject.category
22
23 val pr_notation : notation -> Pp.t
24 (** Printing *)
25
26 module NotationSet : CSet.ExtS with type elt = notation
27 module NotationMap : CMap.ExtS with type key = notation and module Set := NotationSet
28 module SpecificNotationSet : CSet.ExtS with type elt = specific_notation
29 module SpecificNotationMap : CMap.ExtS with type key = specific_notation and module Set := SpecificNotationSet
30
31 (** {6 Scopes } *)
32 (** A scope is a set of interpreters for symbols + optional
33 interpreter and printers for integers + optional delimiters *)
34
35 type delimiters = string
36 type scope
37 type scopes (** = [scope_name list] *)
38
39 val declare_scope : scope_name -> unit
40
41 (* To be removed after deprecation phase *)
42 val ensure_scope : scope_name -> unit
43
44 val current_scopes : unit -> scopes
45
46 (** Check where a scope is opened or not in a scope list, or in
47 * the current opened scopes *)
48 val scope_is_open_in_scopes : scope_name -> scopes -> bool
49 val scope_is_open : scope_name -> bool
50
51 (** Open scope *)
52 val open_scope : scope_name -> unit
53 val close_scope : scope_name -> unit
54
55 (** Return a scope taking either a scope name or delimiter *)
56 val normalize_scope : string -> scope_name
57
58 (** Extend a list of scopes *)
59 val empty_scope_stack : scopes
60 val push_scope : scope_name -> scopes -> scopes
61
62 val find_scope : scope_name -> scope
63
64 val scope_delimiters : scope -> delimiters option
65
66 (** Declare delimiters for printing *)
67
68 val declare_delimiters : scope_name -> delimiters -> unit
69 val remove_delimiters : scope_name -> unit
70 val find_delimiters_scope : ?loc:Loc.t -> delimiters -> scope_name
71
72 (** {6 Declare and uses back and forth an interpretation of primitive token } *)
73
74 (** A number interpreter is the pair of an interpreter for **(hexa)decimal**
75 numbers in terms and an optional interpreter in pattern, if
76 non integer or negative numbers are not supported, the interpreter
77 must fail with an appropriate error message *)
78
79 type notation_location = (DirPath.t * DirPath.t) * string
80 (** 1st dirpath: dirpath of the library
81 2nd dirpath: module and section-only dirpath (ie [Lib.current_dirpath true])
82 string: string used to generate the notation
83
84 dirpaths are used for dumpglob and for Locate, string for printing (pr_notation_info)
85 *)
86
87 type required_module = full_path * string list
88
89 type prim_token_infos = {
90 pt_local : bool; (** Is this interpretation local? *)
91 pt_scope : scope_name; (** Concerned scope *)
92 pt_interp_info : PrimNotations.prim_token_interp_info; (** Unique id "pointing" to (un)interp functions, OR a number notation object describing (un)interp functions *)
93 pt_required : required_module; (** Module that should be loaded first *)
94 pt_refs : GlobRef.t list; (** Entry points during uninterpretation *)
95 pt_in_match : bool (** Is this prim token legal in match patterns ? *)
96 }
97
98 (** Note: most of the time, the [pt_refs] field above will contain
99 inductive constructors (e.g. O and S for nat). But it could also be
100 injection functions such as IZR for reals. *)
101
102 (** Activate a prim token interpretation whose unique id and functions
103 have already been registered. *)
104
105 val enable_prim_token_interpretation : prim_token_infos -> unit
106
107 (** Return the [term]/[cases_pattern] bound to a primitive token in a
108 given scope context*)
109
110 val interp_prim_token : ?loc:Loc.t -> prim_token -> subscopes ->
111 glob_constr * scope_name option
112 (* This function returns a glob_const representing a pattern *)
113 val interp_prim_token_cases_pattern_expr : ?loc:Loc.t -> (Glob_term.glob_constr -> unit) -> prim_token ->
114 subscopes -> glob_constr * scope_name option
115
116 (** Return the primitive token associated to a [term]/[cases_pattern];
117 raise [No_match] if no such token *)
118
119 val uninterp_prim_token :
120 print_float:bool -> 'a glob_constr_g -> subscopes -> prim_token * delimiters option
121 val uninterp_prim_token_cases_pattern :
122 print_float:bool -> 'a cases_pattern_g -> subscopes -> Name.t * prim_token * delimiters option
123
124 val availability_of_prim_token :
125 prim_token -> scope_name -> subscopes -> delimiters option option
126
127 (** {6 Declare and interpret back and forth a notation } *)
128
129 val warning_overridden_name : string
130
131 type entry_coercion_kind =
132 | IsEntryCoercion of notation_entry_level * notation_entry_relative_level
133 | IsEntryGlobal of CustomName.t * int
134 | IsEntryIdent of CustomName.t * int
135
136 val declare_notation : notation_with_optional_scope * notation ->
137 interpretation -> notation_location -> use:notation_use ->
138 entry_coercion_kind option ->
139 UserWarn.t option -> unit
140
141
142 (** Return the interpretation bound to a notation *)
143 val interp_notation : ?loc:Loc.t -> notation -> subscopes ->
144 interpretation * (notation_location * scope_name option)
145
146 (** Test if a notation is available in the scopes
147 context [scopes]; if available, the result is not None; the first
148 argument is itself not None if a delimiters is needed *)
149 val availability_of_notation : specific_notation -> subscopes ->
150 (scope_name option * delimiters option) option
151
152 val is_printing_inactive_rule : Notationextern.interp_rule -> interpretation -> bool
153
154 type 'a notation_query_pattern_gen = {
155 notation_entry_pattern : notation_entry list;
156 interp_rule_key_pattern : (notation_key, 'a) Util.union option;
157 use_pattern : notation_use;
158 scope_pattern : notation_with_optional_scope option;
159 interpretation_pattern : interpretation option;
160 }
161
162 type notation_query_pattern = qualid notation_query_pattern_gen
163
164 val toggle_notations : on:bool -> all:bool -> ?verbose:bool -> (glob_constr -> Pp.t) -> notation_query_pattern -> unit
165
166 (** {6 Miscellaneous} *)
167
168 (** Take a notation string and turn it into a notation key. eg. ["x + y"] becomes ["_ + _"]. *)
169 val interpret_notation_string : string -> string
170
171 type notation_as_reference_error =
172 | AmbiguousNotationAsReference of notation_key
173 | NotationNotReference of Environ.env * Evd.evar_map * notation_key * (notation_key * notation_constr) list
174
175 exception NotationAsReferenceError of notation_as_reference_error
176
177 (** If head is true, also allows applied global references.
178 Raise NotationAsReferenceError if not resolvable as a global reference *)
179 val interp_notation_as_global_reference : ?loc:Loc.t -> head:bool ->
180 (GlobRef.t -> bool) -> notation_key -> delimiters option -> GlobRef.t
181
182 (** Same together with the full notation *)
183 val interp_notation_as_global_reference_expanded : ?loc:Loc.t -> head:bool ->
184 (GlobRef.t -> bool) -> notation_key -> delimiters option ->
185 (notation_entry * notation_key) * notation_key * notation_with_optional_scope * interpretation * GlobRef.t
186
187 (** Declares and looks for scopes associated to arguments of a global ref *)
188 val declare_arguments_scope :
189 bool (** true=local *) -> GlobRef.t -> scope_name list list -> unit
190
191 val find_arguments_scope : Environ.env -> GlobRef.t -> scope_name list list
192
193 type scope_class
194
195 (** Comparison of scope_class *)
196 val scope_class_compare : scope_class -> scope_class -> int
197
198 val subst_scope_class :
199 Environ.env -> Mod_subst.substitution -> scope_class -> scope_class option
200
201 type add_scope_where = AddScopeTop | AddScopeBottom
202 (** add new scope at top or bottom of existing stack (default is reset) *)
203 val declare_scope_class : (* local: *) bool -> scope_name -> ?where:add_scope_where -> scope_class -> unit
204 val declare_ref_arguments_scope : GlobRef.t -> unit
205
206 val compute_arguments_scope : Environ.env -> Evd.evar_map -> EConstr.types -> scope_name list list
207 val compute_type_scope : Environ.env -> Evd.evar_map -> EConstr.types -> scope_name list
208 val compute_glob_type_scope : 'a Glob_term.glob_constr_g -> scope_name list
209
210 (** Get the current scopes bound to Sortclass *)
211 val current_type_scope_names : unit -> scope_name list
212
213 val scope_class_of_class : Coercionops.cl_typ -> scope_class
214
215 (** Building notation key *)
216
217 type symbol =
218 | Terminal of string (* an expression including symbols or a simply-quoted ident, e.g. "'U'" or "!" *)
219 | NonTerminal of Id.t (* an identifier "x" *)
220 | SProdList of Id.t * symbol list (* an expression "x sep .. sep y", remembering x (or y) and sep *)
221 | Break of int (* a sequence of blanks > 1, e.g. " " *)
222
223 val symbol_eq : symbol -> symbol -> bool
224
225 (** Make/decompose a notation of the form "_ U _" *)
226 val make_notation_key : notation_entry -> symbol list -> notation
227 val decompose_notation_key : notation -> notation_entry * symbol list
228
229 type notation_symbols = {
230 recvars : (Id.t * Id.t) list; (* pairs (x,y) as in [ x ; .. ; y ] *)
231 mainvars : Id.t list; (* variables non involved in a recursive pattern *)
232 symbols : symbol list; (* the decomposition of the notation into terminals and nonterminals *)
233 }
234
235 val is_prim_token_constant_in_constr : notation_entry * symbol list -> bool
236
237 (** Decompose a notation of the form "a 'U' b" together with the lists
238 of pairs of recursive variables and the list of all variables
239 binding in the notation *)
240 val decompose_raw_notation : string -> notation_symbols
241
242 (** Prints scopes (expects a pure aconstr printer) *)
243 val pr_scope_class : scope_class -> Pp.t
244 val pr_scope : (glob_constr -> Pp.t) -> scope_name -> Pp.t
245 val pr_scopes : (glob_constr -> Pp.t) -> Pp.t
246 val locate_notation : (glob_constr -> Pp.t) -> notation_key ->
247 scope_name option -> Pp.t
248
249 val pr_visibility: (glob_constr -> Pp.t) -> scope_name option -> Pp.t
250
251 (** Coercions between entries *)
252
253 val is_coercion : notation_entry_level -> notation_entry_relative_level -> bool
254 (** For a rule of the form
255 "Notation string := x (in some-entry, x at some-relative-entry)",
256 tell if going from some-entry to some-relative-entry is coercing *)
257
258 val declare_entry_coercion : specific_notation -> notation_entry_level -> notation_entry_relative_level -> unit
259 (** Add a coercion from some-entry to some-relative-entry *)
260
261 type entry_coercion = (notation_with_optional_scope * notation) list
262 val availability_of_entry_coercion : ?non_included:bool -> notation_entry_relative_level -> notation_entry_level -> entry_coercion option
263 (** Return a coercion path from some-relative-entry to some-entry if there is one *)
264
265 (** Special properties of entries *)
266
267 val declare_custom_entry_has_global : CustomName.t -> int -> unit
268 val declare_custom_entry_has_ident : CustomName.t -> int -> unit
269
270 val entry_has_global : notation_entry_relative_level -> bool
271 val entry_has_ident : notation_entry_relative_level -> bool
272
273 val app_level : int
274
275 val prec_less : entry_level -> entry_relative_level -> bool
276 val may_capture_cont_after : entry_level option -> entry_relative_level -> bool
277
278 (** {6 Declare and test the level of a (possibly uninterpreted) notation } *)
279
280 val declare_notation_level : notation -> level -> unit
281 val level_of_notation : notation -> level
282 (** raise [Not_found] if not declared *)
283
284 (** Rem: printing rules for primitive token are canonical *)
285
286 val with_notation_protection : ('a -> 'b) -> 'a -> 'b