Debian Codegraph @

parsing/procq.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 Genarg
13 open Constrexpr
14 open Libnames
15
16 (** The parser of Rocq *)
17
18 include Gramlib.Grammar.S
19 with type keyword_state := CLexer.keyword_state
20 and type te := Tok.t
21 and type 'a pattern := 'a Tok.p
22 and type 'a with_gstate := 'a
23 and type 'a with_kwstate := 'a
24 and type 'a with_estate := 'a
25 and type 'a mod_estate := 'a
26
27 module Lookahead : sig
28 type t
29 val to_entry : string -> t -> unit Entry.t
30 val (>>) : t -> t -> t
31 val (<+>) : t -> t -> t
32 val lk_empty : t
33 val lk_list : t -> t
34 val check_no_space : t
35 val lk_kw : string -> t
36 val lk_kws : string list -> t
37 val lk_nat : t
38 val lk_ident : t
39 val lk_field : t
40 val lk_name : t
41 val lk_qualid : t
42 val lk_ident_except : string list -> t
43 val lk_ident_list : t
44 end
45
46 (** The parser of Rocq is built from three kinds of rule declarations:
47
48 - dynamic rules declared at the evaluation of Rocq files (using
49 e.g. Notation, Infix, or Tactic Notation)
50 - static rules explicitly defined in files g_*.mlg
51 - static rules macro-generated by ARGUMENT EXTEND, TACTIC EXTEND and
52 VERNAC EXTEND (see e.g. file extratactics.mlg)
53
54 Note that parsing a Rocq document is in essence stateful: the parser
55 needs to recognize commands that start proofs and use a different
56 parsing entry point for them.
57
58 We thus provide two different interfaces: the "raw" parsing
59 interface, in the style of camlp5, which provides more flexibility,
60 and a more specialize "parse_vernac" one, which will indeed adjust
61 the state as needed.
62
63 *)
64
65 (** Dynamic extension of rules
66
67 For constr notations, dynamic addition of new rules is done in
68 several steps:
69
70 - "x + y" (user gives a notation string of type Topconstr.notation)
71 | (together with a constr entry level, e.g. 50, and indications of)
72 | (subentries, e.g. x in constr next level and y constr same level)
73 |
74 | splitting into tokens by Metasyntax.split_notation_string
75 V
76 [String "x"; String "+"; String "y"] : symbol_token list
77 |
78 | interpreted as a mixed parsing/printing production
79 | by Metasyntax.analyse_notation_tokens
80 V
81 [NonTerminal "x"; Terminal "+"; NonTerminal "y"] : symbol list
82 |
83 | translated to a parsing production by Metasyntax.make_production
84 V
85 [GramConstrNonTerminal (ETConstr (NextLevel,(BorderProd Left,LeftA)),
86 Some "x");
87 GramConstrTerminal ("","+");
88 GramConstrNonTerminal (ETConstr (NextLevel,(BorderProd Right,LeftA)),
89 Some "y")]
90 : grammar_constr_prod_item list
91 |
92 | Egrammar.make_constr_prod_item
93 V
94 Gramext.g_symbol list which is sent to camlp5
95
96 For user level tactic notations, dynamic addition of new rules is
97 also done in several steps:
98
99 - "f" constr(x) (user gives a Tactic Notation command)
100 |
101 | parsing
102 V
103 [TacTerm "f"; TacNonTerm ("constr", Some "x")]
104 : grammar_tactic_prod_item_expr list
105 |
106 | Metasyntax.interp_prod_item
107 V
108 [GramTerminal "f";
109 GramNonTerminal (ConstrArgType, Aentry ("constr","constr"), Some "x")]
110 : grammar_prod_item list
111 |
112 | Egrammar.make_prod_item
113 V
114 Gramext.g_symbol list
115
116 For TACTIC/VERNAC/ARGUMENT EXTEND, addition of new rules is done as follows:
117
118 - "f" constr(x) (developer gives an EXTEND rule)
119 |
120 | macro-generation in tacextend.mlg/vernacextend.mlg/argextend.mlg
121 V
122 [GramTerminal "f";
123 GramNonTerminal (ConstrArgType, Aentry ("constr","constr"), Some "x")]
124 |
125 | Egrammar.make_prod_item
126 V
127 Gramext.g_symbol list
128
129 *)
130
131 (** Parse a string *)
132
133 val parse_string : 'a Entry.t -> ?loc:Loc.t -> string -> 'a
134 val eoi_entry : 'a Entry.t -> 'a Entry.t
135
136 val create_generic_entry2 : string ->
137 ('a, rlevel) abstract_argument_type -> 'a Entry.t
138
139 val register_grammar : ('raw, 'glb, 'top) genarg_type -> 'raw Entry.t -> unit
140 val genarg_grammar : ('raw, 'glb, 'top) genarg_type -> 'raw Entry.t
141
142 module Prim :
143 sig
144 open Names
145 open Libnames
146 val preident : string Entry.t
147 val ident : Id.t Entry.t
148 val name : lname Entry.t
149 val identref : lident Entry.t
150 val univ_decl : universe_decl_expr Entry.t
151 val ident_decl : ident_decl Entry.t
152 val pattern_ident : lident Entry.t
153 val bignat : string Entry.t
154 val natural : int Entry.t
155 val bigint : string Entry.t
156 val integer : int Entry.t
157 val string : string Entry.t
158 val lstring : lstring Entry.t
159 val reference : qualid Entry.t
160 val fields : (Id.t list * Id.t) Entry.t
161 val qualid : qualid Entry.t
162 val fullyqualid : Id.t list CAst.t Entry.t
163 val by_notation : (string * string option) Entry.t
164 val smart_global : qualid or_by_notation Entry.t
165 val dirpath : DirPath.t Entry.t
166 val ne_string : string Entry.t
167 val ne_lstring : lstring Entry.t
168 val hyp : lident Entry.t
169 val bar_cbrace : unit Entry.t
170 val strategy_level : Conv_oracle.level Entry.t
171 end
172
173 module Constr :
174 sig
175 val constr : constr_expr Entry.t
176 val constr_eoi : constr_expr Entry.t
177 val lconstr : constr_expr Entry.t
178 val binder_constr : constr_expr Entry.t
179 val term : constr_expr Entry.t
180 val ident : Id.t Entry.t
181 val global : qualid Entry.t
182 val universe_name : sort_name_expr Entry.t
183 val sort : sort_expr Entry.t
184 val sort_quality_or_set : UnivGen.QualityOrSet.t Entry.t
185 val sort_quality_var : quality_expr Entry.t
186 val pattern : cases_pattern_expr Entry.t
187 val constr_pattern : constr_expr Entry.t
188 val cpattern : constr_expr Entry.t
189 val closed_binder : local_binder_expr list Entry.t
190 val binder : local_binder_expr list Entry.t (* closed_binder or variable *)
191 val binders : local_binder_expr list Entry.t (* list of binder *)
192 val open_binders : local_binder_expr list Entry.t
193 val one_open_binder : kinded_cases_pattern_expr Entry.t
194 val one_closed_binder : kinded_cases_pattern_expr Entry.t
195 val binders_fixannot : (local_binder_expr list * fixpoint_order_expr option) Entry.t
196 val typeclass_constraint : (lname * bool * constr_expr) Entry.t
197 val record_declaration : constr_expr Entry.t
198 val arg : (constr_expr * explicitation CAst.t option) Entry.t
199 val type_cstr : constr_expr Entry.t
200 end
201
202 module Module :
203 sig
204 val module_expr : module_ast Entry.t
205 val module_type : module_ast Entry.t
206 end
207
208 (** {5 Type-safe grammar extension} *)
209
210 val epsilon_value : ('a -> 'self) -> ('self, _, 'a) Symbol.t -> 'self option
211
212 (** {5 Extending the parser without synchronization} *)
213
214 val grammar_extend : ignore_kw:bool -> 'a Entry.t -> 'a extend_statement -> unit
215 (** Extend the grammar of Rocq, without synchronizing it with the backtracking
216 mechanism. This means that grammar extensions defined this way will survive
217 an undo. *)
218
219 (** {5 Extending the parser with summary-synchronized commands} *)
220
221 module GramState : Store.S
222 (** Auxiliary state of the grammar. Not marshallable. *)
223
224 val gramstate : unit -> GramState.t
225
226 (** {6 Extension with parsing rules} *)
227
228 type 'a grammar_command
229 (** Type of synchronized parsing extensions. The ['a] type should be
230 marshallable. *)
231
232 type extend_rule =
233 | ExtendRule : 'a Entry.t * 'a extend_statement -> extend_rule
234
235 type 'a grammar_extension = {
236 gext_fun : 'a -> GramState.t -> extend_rule list * GramState.t;
237 gext_eq : 'a -> 'a -> bool;
238 }
239 (** Grammar extension entry point. Given some ['a] and a current grammar state,
240 such a function must produce the list of grammar extensions that will be
241 applied in the same order and kept synchronized w.r.t. the summary, together
242 with a new state. It should be pure. *)
243
244 val create_grammar_command : string -> 'a grammar_extension -> 'a grammar_command
245 (** Create a new grammar-modifying command with the given name. The extension
246 function is called to generate the rules for a given data. *)
247
248 val extend_grammar_command : ignore_kw:bool -> 'a grammar_command -> 'a -> unit
249 (** Extend the grammar of Rocq with the given data. *)
250
251 (** {6 Extension with parsing entries} *)
252
253 (** Used to generate a ['b Entry.t] from a ['a]. ['a] must be marshallable. *)
254 type ('a,'b) entry_extension = {
255 (* Add info about the entry to the state. *)
256 eext_fun : 'a -> 'b Entry.t -> GramState.t -> GramState.t;
257 (* Printing name of the entry. *)
258 eext_name : 'a -> string;
259 (* Comparison function. *)
260 eext_eq : 'a -> 'a -> bool;
261 }
262
263 type ('a,'b) entry_command
264 (** Type of synchronized entry creation. *)
265
266 val create_entry_command : string -> ('a,'b) entry_extension -> ('a,'b) entry_command
267 (** Create a new entry-creating command with the given name. *)
268
269 val extend_entry_command : ('a,'b) entry_command -> 'a -> unit
270 (** Create a new synchronized entry.
271 This is meant to be used by registering the created entry in the GramState with [eext_fun],
272 then when it is needed getting the entry from the GramState. *)
273
274 (** Registering grammars by name *)
275
276 val register_grammars_by_name : string -> Entry.any_t list -> unit
277 val find_grammars_by_name : string -> Entry.any_t list
278
279 (** {6 Protection w.r.t. backtrack} *)
280
281 val with_grammar_rule_protection : ('a -> 'b) -> 'a -> 'b
282
283 type frozen_t
284 val parser_summary_tag : frozen_t Summary.Dyn.tag
285
286 (** Parsing state handling *)
287 val freeze : unit -> frozen_t
288 val unfreeze : frozen_t -> unit
289
290 val get_keyword_state : unit -> CLexer.keyword_state
291
292 val modify_keyword_state : (CLexer.keyword_state -> CLexer.keyword_state) -> unit