Debian Codegraph @

vernac/attributes.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 (** The type of parsing attribute data *)
12 type vernac_flag_type =
13 | FlagQualid of Libnames.qualid
14 | FlagString of string
15
16 type vernac_flags = vernac_flag list
17 and vernac_flag = (string * vernac_flag_value) CAst.t
18 and vernac_flag_value =
19 | VernacFlagEmpty
20 | VernacFlagLeaf of vernac_flag_type
21 | VernacFlagList of vernac_flags
22
23 val pr_vernac_flag : vernac_flag -> Pp.t
24
25 type +'a attribute
26 (** The type of attributes. When parsing attributes if an ['a
27 attribute] is present then an ['a] value will be produced.
28 In the most general case, an attribute transforms the raw flags
29 along with its value. *)
30
31 val parse : 'a attribute -> vernac_flags -> 'a
32 (** Errors on unsupported attributes. *)
33
34 val unsupported_attributes : vernac_flags -> unit
35 (** Errors if the list of flags is nonempty. *)
36
37 module Notations : sig
38 (** Notations to combine attributes. *)
39
40 include Monad.Def with type 'a t = 'a attribute
41 (** Attributes form a monad. [a1 >>= f] means [f] will be run on the
42 flags transformed by [a1] and using the value produced by [a1].
43 The trivial attribute [return x] does no action on the flags. *)
44
45 val (++) : 'a attribute -> 'b attribute -> ('a * 'b) attribute
46 (** Combine 2 attributes. If any keys are in common an error will be raised. *)
47
48 end
49
50 (** Definitions for some standard attributes. *)
51
52 val raw_attributes : vernac_flags attribute
53
54 val polymorphic : bool attribute
55 val poly : PolyFlags.construction_kind -> PolyFlags.t attribute
56 (** Attributes supported by monomorphic or polymorphic constructions depending on their kind *)
57
58 val poly_def : PolyFlags.t attribute
59 (** Attributes supported by monomorphic or polymorphic definitions *)
60
61 val program : bool attribute
62 val template : bool option attribute
63 val unfold_fix : bool attribute
64 val locality : bool option attribute
65 val option_locality : Goptions.option_locality attribute
66 val reversible : bool option attribute
67 val canonical_field : bool attribute
68 val canonical_instance : bool attribute
69 val using : string option attribute
70 val explicit_hint_locality : Hints.hint_locality option attribute
71 val bind_scope_where : Notation.add_scope_where option attribute
72
73 (** "deprecated" *)
74 val deprecation : Deprecation.t option attribute
75 val deprecation_with_use_globref_instead : Globnames.extended_global_reference Deprecation.with_qf option attribute
76
77 (** Just the "warn" attribute *)
78 val user_warn_warn : UserWarn.warn list attribute
79
80 (** "warn" and "deprecated" *)
81 val user_warns : UserWarn.t option attribute
82 val user_warns_with_use_globref_instead : Globnames.extended_global_reference UserWarn.with_qf option attribute
83
84 (** Default: if sections are opened then Local otherwise Export.
85 Although this is named and uses the type [hint_locality]
86 it may be used as the standard 3-valued locality attribute.
87 *)
88 val hint_locality : Hints.hint_locality attribute
89
90 (** Like [hint_locality], but errors on explicit non-Local in sections. *)
91 val hint_locality_no_sections : Hints.hint_locality attribute
92
93 (** Like [hint_locality] but the default in and out of sections is [SuperGlobal]. *)
94 val hint_locality_default_superglobal : Hints.hint_locality attribute
95
96 (** Enable/Disable universe checking *)
97 val typing_flags : Declarations.typing_flags option attribute
98
99 val program_mode_option_name : string list
100 (** For internal use when messing with the global option. *)
101
102 val only_locality : vernac_flags -> bool option
103 (** Parse attributes allowing only locality. *)
104
105 val only_polymorphism : vernac_flags -> bool
106 (** Parse attributes allowing only polymorphism.
107 Uses the global flag for the default value. *)
108
109 val parse_drop_extra : 'a attribute -> vernac_flags -> 'a
110 (** Ignores unsupported attributes. *)
111
112 val parse_with_extra : 'a attribute -> vernac_flags -> vernac_flags * 'a
113 (** Returns unsupported attributes. *)
114
115 (** * Defining attributes. *)
116
117 (** [key_value_attribute ~key ~empty ~values] parses a attribute [key=value]
118 with possible [key,value] in [values], if [empty=Some v] it is for compatibility for users
119 doing [qualif(key)] which is parsed as [qualif(key=v)] *)
120 val key_value_attribute : key:string -> ?empty:'a -> values:(string * 'a) list -> 'a option attribute
121
122 type 'a key_parser = ?loc:Loc.t -> 'a option -> vernac_flag_value -> 'a
123 (** A parser for some key in an attribute. It is given a nonempty ['a
124 option] when the attribute is multiply set for some command.
125
126 eg in [#[polymorphic] Monomorphic Definition foo := ...], when
127 parsing [Monomorphic] it will be given [Some true]. *)
128
129 val attribute_of_list : (string * 'a key_parser) list -> 'a option attribute
130 (** Make an attribute from a list of key parsers together with their
131 associated key. *)
132
133 val payload_parser : ?cat:(string -> string -> string) -> name:string -> string key_parser
134 (** [payload_parser ?cat ~name] parses attributes like [#[name="payload"]].
135 If the attribute is used multiple times and [cat] is non-None,
136 the payloads are concatenated using it.
137 If [cat] is None, having multiple occurences of the attribute is forbidden. *)
138
139 val payload_attribute : ?cat:(string -> string -> string) -> name:string -> string option attribute
140 (** This is just [attribute_of_list] for a single [payload_parser]. *)
141
142 (** Define boolean attribute [name], of the form [name={yes,no}]. The
143 attribute may only be set once for a command. *)
144 val bool_attribute : name:string -> bool option attribute
145
146 val qualify_attribute : string -> 'a attribute -> 'a attribute
147 (** [qualified_attribute qual att] treats [#[qual(atts)]] like [att]
148 treats [atts]. *)
149
150 (** Combinators to help define your own parsers. See the
151 implementation of [bool_attribute] for practical use. *)
152
153 val assert_empty : ?loc:Loc.t -> string -> vernac_flag_value -> unit
154 (** [assert_empty key v] errors if [v] is not empty. [key] is used in
155 the error message as the name of the attribute. *)
156
157 val assert_once : ?loc:Loc.t -> name:string -> 'a option -> unit
158 (** [assert_once ~name v] errors if [v] is not empty. [name] is used
159 in the error message as the name of the attribute. Used to ensure
160 that a given attribute is not reapeated. *)
161
162 val single_key_parser : name:string -> key:string -> 'a -> 'a key_parser
163 (** [single_key_parser ~name ~key v] makes a parser for attribute
164 [name] giving the constant value [v] for key [key] taking no
165 arguments. [name] may only be given once. *)
166
167 val make_attribute : (vernac_flags -> vernac_flags * 'a) -> 'a attribute
168 (** Make an attribute using the internal representation, thus with
169 access to the full power of attributes. Unstable. *)
170
171 (** Compatibility values for parsing [Polymorphic]. *)
172 val vernac_polymorphic_flag : Loc.t option -> vernac_flag
173 val vernac_monomorphic_flag : Loc.t option -> vernac_flag
174
175 (** For internal use. *)
176 val universe_polymorphism_option_name : string list
177 val is_universe_polymorphism : unit -> bool