Debian Codegraph @

vernac/g_vernac.mlg

raw
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 DECLARE GLOBAL PLUGIN
12
13 {
14
15 open Pp
16 open Util
17 open Names
18 open Glob_term
19 open Vernacexpr
20 open Constrexpr
21 open Constrexpr_ops
22 open Extend
23 open Decls
24 open Declaremods
25
26 module C = Constr
27
28 open Procq
29 open Procq.Prim
30 open Procq.Constr
31 open Procq.Module
32 open Pvernac.Vernac_
33 open Attributes
34
35 (* Rem: do not join the different GEXTEND into one, it breaks native *)
36 (* compilation on PowerPC and Sun architectures *)
37
38 let query_command = Entry.make "query_command"
39
40 let search_query = Entry.make "search_query"
41 let search_queries = Entry.make "search_queries"
42
43 let subprf = Entry.make "subprf"
44 let subprf_with_selector = Entry.make "subprf_with_selector"
45
46 let quoted_attributes = Entry.make "quoted_attributes"
47 let attribute_list = Entry.make "attribute_list"
48 let coercion_class = Entry.make "coercion_class"
49 let thm_token = Entry.make "thm_token"
50 let def_token = Entry.make "def_token"
51 let assumption_token = Entry.make "assumption_token"
52 let def_body = Entry.make "def_body"
53 let notation_declaration = Entry.make "notation_declaration"
54 let decl_notations = Entry.make "decl_notations"
55 let record_field = Entry.make "record_field"
56 let of_type = Entry.make "of_type"
57 let of_type_inst = Entry.make "of_type_inst"
58 let section_subset_expr = Entry.make "section_subset_expr"
59 let scope_delimiter = Entry.make "scope_delimiter"
60 let syntax_modifiers = Entry.make "syntax_modifiers"
61 let goal_selector = Entry.make "goal_selector"
62 let toplevel_selector = Entry.make "toplevel_selector"
63
64 let make_bullet s =
65 let open Proof_bullet in
66 let n = String.length s in
67 match s.[0] with
68 | '-' -> Dash n
69 | '+' -> Plus n
70 | '*' -> Star n
71 | _ -> assert false
72
73 let test_hash_ident =
74 let open Procq.Lookahead in
75 to_entry "test_hash_ident" begin
76 lk_kw "#" >> lk_ident >> check_no_space
77 end
78
79 let test_id_colon =
80 let open Procq.Lookahead in
81 to_entry "test_id_colon" begin
82 lk_ident >> lk_kw ":"
83 end
84
85 let warn_chdir_pwd = CWarnings.create ~name:"change-dir-pwd-deprecated" ~category:Deprecation.Version.v8_20
86 (fun () -> strbrk "Command \"Cd\" as a synonym of \"Pwd\" is deprecated." ++ spc () ++
87 strbrk "Use \"Pwd\" instead.")
88
89 }
90
91 GRAMMAR EXTEND Gram
92 GLOBAL: vernac_control quoted_attributes attribute_list gallina_ext noedit_mode subprf subprf_with_selector qualid;
93 vernac_control: FIRST
94 [ [ control = LIST0 control_flag; v = decorated_vernac ->
95 { let (attrs, expr) = v in CAst.make ~loc { control; attrs; expr; } } ]
96 ]
97 ;
98 control_flag:
99 [ [ IDENT "Time" -> { CAst.make ~loc ControlTime }
100 | IDENT "Instructions" -> { CAst.make ~loc ControlInstructions }
101 | IDENT "Profile"; f = OPT STRING -> { CAst.make ~loc (ControlProfile f) }
102 | IDENT "Redirect"; s = ne_string -> { CAst.make ~loc (ControlRedirect s) }
103 | IDENT "Timeout"; n = natural -> { CAst.make ~loc (ControlTimeout n) }
104 | IDENT "Fail" -> { CAst.make ~loc ControlFail }
105 | IDENT "Succeed" -> { CAst.make ~loc ControlSucceed }
106 ] ]
107 ;
108 decorated_vernac:
109 [ [ a = quoted_attributes ; a' = LIST0 legacy_attr; v = vernac_aux ->
110 { (List.append a a', v) } ] ]
111 ;
112 quoted_attributes:
113 [ [ l = LIST0 [ "#[" ; a = attribute_list ; "]" -> { a } ] -> { List.flatten l } ]
114 ]
115 ;
116 attribute_list:
117 [ [ a = LIST1 attribute SEP "," -> { a } ]
118 ]
119 ;
120 attribute:
121 [ [ k = ident ; v = attr_value -> { CAst.make ~loc (Names.Id.to_string k, v) }
122 (* Required because "ident" is declared a keyword when loading Ltac. *)
123 | IDENT "using" ; v = attr_value -> { CAst.make ~loc ("using", v) } ]
124 ]
125 ;
126 attr_value:
127 [ [ "=" ; v = string -> { VernacFlagLeaf (FlagString v) }
128 | "=" ; v = qualid -> { VernacFlagLeaf (FlagQualid v) }
129 | "(" ; a = attribute_list ; ")" -> { VernacFlagList a }
130 | -> { VernacFlagEmpty } ]
131 ]
132 ;
133 legacy_attr:
134 [ [ IDENT "Local" ->
135 { CAst.make ~loc ("local", VernacFlagEmpty) }
136 | IDENT "Global" ->
137 { CAst.make ~loc ("global", VernacFlagEmpty) }
138 | IDENT "Polymorphic" ->
139 { Attributes.vernac_polymorphic_flag (Some loc) }
140 | IDENT "Monomorphic" ->
141 { Attributes.vernac_monomorphic_flag (Some loc) }
142 | IDENT "Cumulative" ->
143 { CAst.make ~loc ("universes", VernacFlagList [CAst.make ~loc ("cumulative", VernacFlagEmpty)]) }
144 | IDENT "NonCumulative" ->
145 { CAst.make ~loc ("universes", VernacFlagList [CAst.make ~loc ("cumulative", VernacFlagLeaf (FlagQualid (Libnames.qualid_of_string "no")))]) }
146 | IDENT "Private" ->
147 { CAst.make ~loc ("private", VernacFlagList [CAst.make ~loc ("matching", VernacFlagEmpty)]) }
148 | IDENT "Program" ->
149 { CAst.make ~loc ("program", VernacFlagEmpty) }
150 ] ]
151 ;
152 vernac_aux:
153 (* Better to parse "." here: in case of failure (e.g. in coerce_to_var), *)
154 (* "." is still in the stream and discard_to_dot works correctly *)
155 [ [ g = gallina; "." -> { VernacSynPure g }
156 | g = gallina_ext; "." -> { g }
157 | c = command; "." -> { c }
158 | c = syntax; "." -> { c }
159 ] ]
160 ;
161 vernac_aux: LAST
162 [ [ prfcom = command_entry -> { prfcom } ] ]
163 ;
164
165 noedit_mode: [ [ c = query_command -> { VernacSynPure (c None) } ] ]
166 ;
167
168 subprf:
169 [ [ s = BULLET -> { VernacBullet (make_bullet s) }
170 | "}" -> { VernacEndSubproof }
171 ] ]
172 ;
173 subprf_with_selector:
174 [ [ "{" -> { fun g -> VernacSubproof g }
175 (* query_command needs to be here to factor with VernacSubproof *)
176 | c = query_command -> { c }
177 ] ]
178 ;
179
180 END
181
182 {
183
184 let warn_plural_command =
185 CWarnings.create ~name:"plural-command" ~category:CWarnings.CoreCategories.pedantic ~default:CWarnings.Disabled
186 (fun kwd -> strbrk (Printf.sprintf "Command \"%s\" expects more than one assumption." kwd))
187
188 let test_plural_form loc kwd = function
189 | [(_,([_],_))] ->
190 warn_plural_command ~loc kwd
191 | _ -> ()
192
193 let test_plural_form_types loc kwd = function
194 | [([_],_)] ->
195 warn_plural_command ~loc kwd
196 | _ -> ()
197
198 let test_plural_form_rules loc kwd = function
199 | [_] ->
200 warn_plural_command ~loc kwd
201 | _ -> ()
202
203 let lname_of_lident : lident -> lname =
204 CAst.map (fun s -> Name s)
205
206 let name_of_ident_decl : ident_decl -> name_decl =
207 on_fst lname_of_lident
208
209 let test_variance_ident =
210 let open Procq.Lookahead in
211 to_entry "test_variance_ident" begin
212 lk_kws ["=";"+";"*"] >> lk_ident
213 end
214
215 let test_doublepipe_univ_decl =
216 let open Procq.Lookahead in
217 to_entry "test_doublepipe_univ_decl" (lk_ident_list >> lk_kw "|" >> lk_ident_list >> (lk_kw "+" <+> lk_empty) >> (lk_kw "|" <+> lk_kw "|}"))
218
219 let test_doublepipe_cumul_univ_decl =
220 let open Procq.Lookahead in
221 let lk_list_variance_ident = lk_list (lk_kw "+" <+> lk_kw "*" <+> lk_kw "=" <+> lk_ident) in
222 to_entry "test_doublepipe_cumul_univ_decl" (lk_ident_list >> lk_kw "|" >> lk_list_variance_ident >> (lk_kw "+" <+> lk_empty) >> (lk_kw "|" <+> lk_kw "|}"))
223
224 let test_semicolon_cumul_univ_decl =
225 let open Procq.Lookahead in
226 to_entry "test_semicolon_cumul_univ_decl" (lk_ident_list >> lk_kw ";")
227
228 let test_univ_cst =
229 let open Procq.Lookahead in
230 let univ = lk_qualid <+> lk_kws ["Set";"Prop"] in
231 to_entry "test_univ_cst" (univ >> lk_kws ["<"; "="; "<="] >> univ)
232
233 let rec elim_constraints = function
234 | [] -> []
235 | ElimCst (q1,k,q2) :: t -> (q1,k,q2) :: elim_constraints t
236 | h :: t -> elim_constraints t
237
238 let rec univ_constraints = function
239 | [] -> []
240 | UnivCst (l1,k,l2) :: t -> (l1,k,l2) :: univ_constraints t
241 | h :: t -> univ_constraints t
242
243 }
244
245 (* Gallina declarations *)
246 GRAMMAR EXTEND Gram
247 GLOBAL: gallina gallina_ext thm_token def_token assumption_token def_body of_type of_type_inst
248 record_field notation_declaration decl_notations fix_definition ident_decl univ_decl inductive_or_record_definition;
249
250 gallina:
251 (* Definition, Theorem, Variable, Axiom, ... *)
252 [ [ thm = thm_token; id = ident_decl; bl = binders; ":"; c = lconstr;
253 l = LIST0
254 [ "with"; id = ident_decl; bl = binders; ":"; c = lconstr ->
255 { (id,(bl,c)) } ] ->
256 { VernacStartTheoremProof (thm, (id,(bl,c))::l) }
257 | stre = assumption_token; nl = inline; bl = assum_list ->
258 { VernacAssumption (stre, nl, bl) }
259 | tk = assumptions_token; nl = inline; bl = assum_list ->
260 { let (kwd,stre) = tk in
261 test_plural_form loc kwd bl;
262 VernacAssumption (stre, nl, bl) }
263 | d = def_token; id = ident_decl; b = def_body ->
264 { VernacDefinition (d, name_of_ident_decl id, b) }
265 | IDENT "Symbol"; bl = assum_list ->
266 { VernacSymbol bl }
267 | IDENT "Symbols"; bl = assum_list ->
268 { test_plural_form loc "Symbols" bl;
269 VernacSymbol bl }
270 | IDENT "Let"; id = ident_decl; b = def_body ->
271 { VernacDefinition ((DoDischarge, Let), name_of_ident_decl id, b) }
272 (* Gallina inductive declarations *)
273 | f = finite_token; ind = inductive_or_record_definition ->
274 { VernacInductive (f, [ind]) }
275 | f = inductive_token; indl = LIST1 inductive_or_record_definition SEP "with" ->
276 { VernacInductive (f, indl) }
277 | "Fixpoint"; recs = LIST1 fix_definition SEP "with" ->
278 { VernacFixpoint (NoDischarge, List.split recs) }
279 | IDENT "Let"; "Fixpoint"; recs = LIST1 fix_definition SEP "with" ->
280 { VernacFixpoint (DoDischarge, List.split recs) }
281 | "CoFixpoint"; corecs = LIST1 cofix_definition SEP "with" ->
282 { VernacCoFixpoint (NoDischarge, corecs) }
283 | IDENT "Let"; "CoFixpoint"; corecs = LIST1 cofix_definition SEP "with" ->
284 { VernacCoFixpoint (DoDischarge, corecs) }
285 | IDENT "Scheme"; IDENT "All"; IDENT "for" ; id = smart_global ; strpos = OPT [IDENT "over" ; l = LIST1 ident SEP "," -> {l}] ->
286 { VernacSchemeAll (id, strpos) }
287 | IDENT "Scheme"; l = LIST1 scheme SEP "with" -> { VernacScheme l }
288 | IDENT "Scheme"; IDENT "Equality"; IDENT "for" ; id = smart_global ->
289 { VernacSchemeEquality (SchemeEquality,id) }
290 | IDENT "Scheme"; IDENT "Boolean"; IDENT "Equality"; IDENT "for" ; id = smart_global ->
291 { VernacSchemeEquality (SchemeBooleanEquality,id) }
292 | IDENT "Scheme"; IDENT "Rewriting"; IDENT "for" ; id = smart_global ->
293 { VernacSchemeEquality (SchemeRewriting,id) }
294 | IDENT "Combined"; IDENT "Scheme"; id = identref; IDENT "from";
295 l = LIST1 identref SEP "," -> { VernacCombinedScheme (id, l) }
296 | IDENT "Register"; g = global; "as"; quid = qualid ->
297 { VernacRegister(g, RegisterCoqlib quid) }
298 | IDENT "Register"; IDENT "Scheme"; g = global; "as"; qid = qualid; IDENT "for"; g' = global ->
299 { VernacRegister(g, RegisterScheme {inductive = g'; scheme_kind = qid}) }
300 | IDENT "Register"; IDENT "Inline"; g = global ->
301 { VernacRegister(g, RegisterInline) }
302 | IDENT "Primitive"; id = ident_decl; typopt = OPT [ ":"; typ = lconstr -> { typ } ]; ":="; r = register_token ->
303 { VernacPrimitive(id, r, typopt) }
304 | IDENT "Universe"; l = LIST1 identref -> { VernacUniverse l }
305 | IDENT "Universes"; l = LIST1 identref -> { VernacUniverse l }
306 | IDENT "Sort"; l = LIST1 identref -> { VernacSort l }
307 | IDENT "Sorts"; l = LIST1 identref -> { VernacSort l }
308 | IDENT "Constraint"; l = LIST1 sort_constraint SEP "," -> { VernacConstraint l }
309 | IDENT "Rewrite"; IDENT "Rule"; id = identref; ":="; OPT"|"; rules = LIST1 rewrite_rule SEP "|" ->
310 { VernacAddRewRule (id, rules) }
311 | IDENT "Rewrite"; IDENT "Rules"; id = identref; ":="; OPT"|"; rules = LIST1 rewrite_rule SEP "|" ->
312 { test_plural_form_rules loc "Rewrite Rules" rules;
313 VernacAddRewRule (id, rules) }
314 ] ]
315 ;
316 register_token:
317 [ [ test_hash_ident; "#"; r = IDENT -> { CPrimitives.parse_op_or_type ~loc r } ] ]
318 ;
319 thm_token:
320 [ [ "Theorem" -> { Theorem }
321 | IDENT "Lemma" -> { Lemma }
322 | IDENT "Fact" -> { Fact }
323 | IDENT "Remark" -> { Remark }
324 | IDENT "Corollary" -> { Corollary }
325 | IDENT "Proposition" -> { Proposition }
326 | IDENT "Property" -> { Property } ] ]
327 ;
328 def_token:
329 [ [ "Definition" -> { (NoDischarge,Definition) }
330 | IDENT "Example" -> { (NoDischarge,Example) }
331 | IDENT "SubClass" -> { (NoDischarge,SubClass) } ] ]
332 ;
333 assumption_token:
334 [ [ "Hypothesis" -> { (DoDischarge, Logical) }
335 | "Variable" -> { (DoDischarge, Definitional) }
336 | "Axiom" -> { (NoDischarge, Logical) }
337 | "Parameter" -> { (NoDischarge, Definitional) }
338 | IDENT "Conjecture" -> { (NoDischarge, Conjectural) } ] ]
339 ;
340 assumptions_token:
341 [ [ IDENT "Hypotheses" -> { ("Hypotheses", (DoDischarge, Logical)) }
342 | IDENT "Variables" -> { ("Variables", (DoDischarge, Definitional)) }
343 | IDENT "Axioms" -> { ("Axioms", (NoDischarge, Logical)) }
344 | IDENT "Parameters" -> { ("Parameters", (NoDischarge, Definitional)) }
345 | IDENT "Conjectures" -> { ("Conjectures", (NoDischarge, Conjectural)) } ] ]
346 ;
347 inline:
348 [ [ IDENT "Inline"; "("; i = natural; ")" -> { InlineAt i }
349 | IDENT "Inline" -> { DefaultInline }
350 | -> { NoInline } ] ]
351 ;
352 sort_constraint:
353 [ [ test_univ_cst; l = universe_name;
354 ord = [ "<" -> { Univ.UnivConstraint.Lt } | "=" -> { Univ.UnivConstraint.Eq } | "<=" -> { Univ.UnivConstraint.Le } ];
355 r = universe_name -> { UnivCst (l, ord, r) }
356 | l = sort_quality_var; "->"; r = sort_quality_var
357 -> { ElimCst (l, Sorts.ElimConstraint.ElimTo, r) } ] ]
358 ;
359 univ_decl_constraints:
360 [ [ "|"; l' = LIST0 sort_constraint SEP ",";
361 ext = [ "+" -> { true } | -> { false } ]; "}" -> { (l',ext) }
362 | ext = [ "}" -> { true } | bar_cbrace -> { false } ] -> { ([], ext) } ] ]
363 ;
364 univ_decl:
365 [ [ "@{" ; test_doublepipe_univ_decl; l0 = LIST0 identref; pipe_loc = [ "|" -> { loc } ]; l = LIST0 identref; ext = [ "+" -> { true } | -> { false } ];
366 cs = univ_decl_constraints
367 ->
368 { let open UState in
369 G_constr.warn_old_sort_syntax ~loc:pipe_loc ();
370 { univdecl_qualities = l0;
371 univdecl_extensible_qualities = false;
372 univdecl_elim_constraints = elim_constraints @@ fst cs;
373 univdecl_instance = l;
374 univdecl_extensible_instance = ext;
375 univdecl_univ_constraints = univ_constraints @@ fst cs;
376 univdecl_extensible_constraints = snd cs } }
377 | "@{" ; l0 = LIST0 identref; ";"; l = LIST0 identref; ext = [ "+" -> { true } | -> { false } ];
378 cs = univ_decl_constraints
379 ->
380 { let open UState in
381 { univdecl_qualities = l0;
382 univdecl_extensible_qualities = false;
383 univdecl_elim_constraints = elim_constraints @@ fst cs;
384 univdecl_instance = l;
385 univdecl_extensible_instance = ext;
386 univdecl_univ_constraints = univ_constraints @@ fst cs;
387 univdecl_extensible_constraints = snd cs } }
388 | "@{" ; l = LIST0 identref; ext = [ "+" -> { true } | -> { false } ];
389 cs = univ_decl_constraints
390 ->
391 { let open UState in
392 { univdecl_qualities = [];
393 univdecl_extensible_qualities = false;
394 univdecl_elim_constraints = elim_constraints @@ fst cs;
395 univdecl_instance = l;
396 univdecl_extensible_instance = ext;
397 univdecl_univ_constraints = univ_constraints @@ fst cs;
398 univdecl_extensible_constraints = snd cs } }
399 ] ]
400 ;
401 variance:
402 [ [ "+" -> { UVars.Variance.Covariant }
403 | "=" -> { UVars.Variance.Invariant }
404 | "*" -> { UVars.Variance.Irrelevant }
405 ] ]
406 ;
407 variance_identref:
408 [ [ id = identref -> { (id, None) }
409 | test_variance_ident; v = variance; id = identref -> { (id, Some v) }
410 (* We need this test to help the parser avoid the conflict
411 between "+" before ident (covariance) and trailing "+" (extra univs allowed) *)
412 ] ]
413 ;
414 cumul_univ_decl:
415 [ [ "@{" ; test_doublepipe_cumul_univ_decl; l0 = LIST0 identref; pipe_loc = [ "|" -> { loc } ];
416 l = LIST0 variance_identref; ext = [ "+" -> { true } | -> { false } ];
417 cs = univ_decl_constraints
418 ->
419 { let open UState in
420 G_constr.warn_old_sort_syntax ~loc:pipe_loc ();
421 { univdecl_qualities = l0;
422 univdecl_extensible_qualities = false;
423 univdecl_elim_constraints = elim_constraints @@ fst cs;
424 univdecl_instance = l;
425 univdecl_extensible_instance = ext;
426 univdecl_univ_constraints = univ_constraints @@ fst cs;
427 univdecl_extensible_constraints = snd cs } }
428
429 | "@{" ; test_semicolon_cumul_univ_decl; l0 = LIST0 identref; ";";
430 l = LIST0 variance_identref; ext = [ "+" -> { true } | -> { false } ];
431 cs = univ_decl_constraints
432 ->
433 { let open UState in
434 { univdecl_qualities = l0;
435 univdecl_extensible_qualities = false;
436 univdecl_elim_constraints = elim_constraints @@ fst cs;
437 univdecl_instance = l;
438 univdecl_extensible_instance = ext;
439 univdecl_univ_constraints = univ_constraints @@ fst cs;
440 univdecl_extensible_constraints = snd cs } }
441
442 | "@{" ; l = LIST0 variance_identref; ext = [ "+" -> { true } | -> { false } ];
443 cs = univ_decl_constraints
444 ->
445 { let open UState in
446 { univdecl_qualities = [];
447 univdecl_extensible_qualities = false;
448 univdecl_elim_constraints = elim_constraints @@ fst cs;
449 univdecl_instance = l;
450 univdecl_extensible_instance = ext;
451 univdecl_univ_constraints = univ_constraints @@ fst cs;
452 univdecl_extensible_constraints = snd cs } }
453 ] ]
454 ;
455 ident_decl:
456 [ [ i = identref; l = OPT univ_decl -> { (i, l) }
457 ] ]
458 ;
459 cumul_ident_decl:
460 [ [ i = identref; l = OPT cumul_univ_decl -> { (i, l) }
461 ] ]
462 ;
463 inductive_token:
464 [ [ IDENT "Inductive" -> { Inductive_kw }
465 | IDENT "CoInductive" -> { CoInductive } ] ]
466 ;
467 finite_token:
468 [ [ IDENT "Variant" -> { Variant }
469 | IDENT "Record" -> { Record }
470 | IDENT "Structure" -> { Structure }
471 | IDENT "Class" -> { Class true } ] ]
472 ;
473 (* Simple definitions *)
474 def_body:
475 [ [ bl = binders; ":="; red = reduce; c = lconstr ->
476 { match c.CAst.v with
477 | CCast(c, Some C.DEFAULTcast, t) -> DefineBody (bl, red, c, Some t)
478 | _ -> DefineBody (bl, red, c, None) }
479 | bl = binders; ":"; t = lconstr; ":="; red = reduce; c = lconstr ->
480 { DefineBody (bl, red, c, Some t) }
481 | bl = binders; ":"; t = lconstr ->
482 { ProveBody (bl, t) } ] ]
483 ;
484 reduce:
485 [ [ IDENT "Eval"; r = red_expr; "in" -> { Some r }
486 | -> { None } ] ]
487 ;
488 notation_declaration:
489 [ [ ntn = lstring; ":="; c = constr;
490 modl = syntax_modifiers;
491 scopt = OPT [ ":"; sc = IDENT -> { sc } ] ->
492 { { ntn_decl_string = ntn; ntn_decl_interp = c;
493 ntn_decl_scope = scopt;
494 ntn_decl_modifiers = modl;
495 } } ] ]
496 ;
497 decl_sep:
498 [ [ IDENT "and" -> { () } ] ]
499 ;
500 decl_notations:
501 [ [ "where"; l = LIST1 notation_declaration SEP decl_sep -> { l }
502 | -> { [] } ] ]
503 ;
504 (* Inductives and records *)
505 opt_constructors_or_fields:
506 [ [ ":="; lc = constructors_or_record -> { lc }
507 | ":=" -> { Constructors [] }
508 | -> { RecordDecl (None, [], None) } ] ]
509 ;
510 inductive_or_record_definition:
511 [ [ oc = opt_coercion; id = cumul_ident_decl; indpar = binders;
512 extrapar = OPT [ "|"; p = binders -> { p } ];
513 c = OPT [ ":"; c = lconstr -> { c } ];
514 lc=opt_constructors_or_fields; ntn = decl_notations ->
515 { (((oc,id),(indpar,extrapar),c,lc),ntn) } ] ]
516 ;
517 constructors_or_record:
518 [ [ "|"; l = LIST1 constructor SEP "|" -> { Constructors l }
519 | attr = quoted_attributes ; id = identref ; c = constructor_type;
520 "|"; l = LIST1 constructor SEP "|" ->
521 { Constructors ((c attr id)::l) }
522 | attr = quoted_attributes ; id = identref ; c = constructor_type ->
523 { Constructors [ c attr id ] }
524 | attr = quoted_attributes ;
525 cstr = identref; "{"; fs = record_fields; "}"; id = default_inhabitant_ident ->
526 { let () = unsupported_attributes attr in
527 RecordDecl (Some cstr,fs,id) }
528 | "{";fs = record_fields; "}"; id = default_inhabitant_ident -> { RecordDecl (None,fs,id) } ] ]
529 ;
530 default_inhabitant_ident:
531 [ [ "as"; id = identref -> { Some id }
532 | -> { None } ] ]
533 ;
534 (*
535 csort:
536 [ [ s = sort -> CSort (loc,s) ] ]
537 ;
538 *)
539 opt_coercion:
540 [ [ ">" -> { AddCoercion }
541 | -> { NoCoercion } ] ]
542 ;
543 (* (co)-fixpoints *)
544 fix_definition:
545 [ [ id_decl = ident_decl;
546 bl = binders_fixannot;
547 rtype = type_cstr;
548 body_def = OPT [":="; def = lconstr -> { def } ]; notations = decl_notations ->
549 { let binders, rec_order = bl in
550 ((rec_order : Constrexpr.fixpoint_order_expr option), {fname = fst id_decl; univs = snd id_decl; binders; rtype; body_def; notations})
551 } ] ]
552 ;
553 cofix_definition:
554 [ [ id_decl = ident_decl; binders = binders; rtype = type_cstr;
555 body_def = OPT [":="; def = lconstr -> { def }]; notations = decl_notations ->
556 { {fname = fst id_decl; univs = snd id_decl; binders; rtype; body_def; notations}
557 } ]]
558 ;
559 (* Rewrite Rules *)
560 rw_pattern:
561 [ [ p = lconstr -> { p } ] ];
562 rewrite_rule:
563 [ [ u = OPT [ u = univ_decl; "|-" -> { u }];
564 lhs = rw_pattern; "=>" ; rhs = lconstr ->
565 { (u, lhs, rhs)
566 } ] ]
567 ;
568 (* Inductive schemes *)
569 scheme:
570 [ [ kind = scheme_kind -> { (None,kind) }
571 | id = identref; ":="; kind = scheme_kind -> { (Some id,kind) } ] ]
572 ;
573 scheme_kind:
574 [ [sch_type = scheme_type; "for"; sch_qualid = smart_global; IDENT "Sort"; sch_sort = sort_quality_or_set
575 -> { {sch_type; sch_qualid; sch_sort} }
576 ] ]
577 ;
578 scheme_type:
579 [ [ IDENT "Induction" -> { SchemeInduction }
580 | IDENT "Minimality" -> { SchemeMinimality }
581 | IDENT "Elimination" -> { SchemeElimination }
582 | IDENT "Case" -> { SchemeCase }
583 ] ]
584 ;
585 (* Various Binders *)
586 (*
587 (* ... without coercions *)
588 binder_nodef:
589 [ [ b = binder_let ->
590 (match b with
591 CLocalAssum(l,ty) -> (l,ty)
592 | CLocalDef _ ->
593 user_err ~loc
594 (Pp.str"defined binder not allowed here.")) ] ]
595 ;
596 *)
597 (* ... with coercions *)
598 record_field:
599 [ [ rfu_attrs = quoted_attributes ;
600 bd = record_binder; rfu_priority = OPT [ "|"; n = natural -> { n } ];
601 rfu_notation = decl_notations -> {
602 let (rfu_coercion, rfu_instance), rf_decl = bd in
603 rf_decl,
604 { rfu_attrs ; rfu_coercion ; rfu_instance ; rfu_priority ;
605 rfu_notation } } ] ]
606 ;
607 record_fields:
608 [ RIGHTA [ f = record_field; ";"; fs = record_fields -> { f :: fs }
609 | f = record_field -> { [f] }
610 | -> { [] }
611 ] ]
612 ;
613 field_body:
614 [ [ l = binders; oc = of_type_inst;
615 t = lconstr -> { fun id -> (oc,AssumExpr (id,l,t)) }
616 | l = binders; oc = of_type_inst;
617 t = lconstr; ":="; b = lconstr -> { fun id ->
618 (oc,DefExpr (id,l,b,Some t)) }
619 | l = binders; ":="; b = lconstr -> { fun id ->
620 (* Why are we dropping cast info here? *)
621 match b.CAst.v with
622 | CCast(b', _, t) ->
623 ((NoCoercion,NoInstance),DefExpr(id,l,b',Some t))
624 | _ ->
625 ((NoCoercion,NoInstance),DefExpr(id,l,b,None)) } ] ]
626 ;
627 record_binder:
628 [ [ id = name -> { ((NoCoercion,NoInstance),AssumExpr(id, [], CAst.make ~loc @@ CHole (None))) }
629 | id = name; f = field_body -> { f id } ] ]
630 ;
631 assum_list:
632 [ [ bl = LIST1 assum_coe -> { bl } | b = assumpt -> { [b] } ] ]
633 ;
634 assum_coe:
635 [ [ "("; a = assumpt; ")" -> { a } ] ]
636 ;
637 assumpt:
638 [ [ idl = LIST1 ident_decl; oc = of_type; c = lconstr ->
639 { (oc,(idl,c)) } ] ]
640 ;
641
642 constructor_type:
643 [[ l = binders;
644 t= [ coe = of_type_inst; c = lconstr ->
645 { fun l attr id -> ((attr, fst coe, snd coe),(id,mkProdCN ~loc l c)) }
646 | ->
647 { fun l attr id -> ((attr,NoCoercion,NoInstance),(id,mkProdCN ~loc l (CAst.make ~loc @@ CHole (None)))) } ]
648 -> { t l }
649 ]]
650 ;
651
652 constructor:
653 [ [ attr = quoted_attributes ;
654 id = identref; c=constructor_type -> { c attr id } ] ]
655 ;
656 of_type:
657 [ [ ":>" -> { AddCoercion }
658 | ":"; ">" -> { AddCoercion }
659 | ":" -> { NoCoercion } ] ]
660 ;
661 of_type_inst:
662 [ [ ":>" -> { (AddCoercion, NoInstance) }
663 | ":"; ">" -> { (AddCoercion, NoInstance) }
664 | "::" -> { (NoCoercion, BackInstance) }
665 | "::>" -> { (AddCoercion, BackInstance) }
666 | ":" -> { (NoCoercion, NoInstance) } ] ]
667 ;
668 END
669
670 {
671
672 let test_only_starredidentrefs =
673 let open Procq.Lookahead in
674 to_entry "test_only_starredidentrefs" begin
675 lk_list (lk_ident <+> lk_kws ["Type"; "*"]) >> (lk_kws [".";")"])
676 end
677
678 let starredidentreflist_to_expr l =
679 match l with
680 | [] -> SsEmpty
681 | x :: xs -> List.fold_right (fun i acc -> SsUnion(i,acc)) xs x
682
683 let warn_deprecated_include_type =
684 CWarnings.create ~name:"deprecated-include-type" ~category:Deprecation.Version.v8_3
685 (fun () -> strbrk "Include Type is deprecated; use Include instead")
686
687 let warn_deprecated_as_ident_kind =
688 CWarnings.create ~name:"deprecated-as-ident-kind" ~category:Deprecation.Version.v8_14
689 (fun () -> strbrk "grammar kind \"as ident\" no longer accepts \"_\"; use \"as name\" instead to accept \"_\", too, or silence the warning if you actually intended to accept only identifiers.")
690
691 }
692
693 (* Modules and Sections *)
694 GRAMMAR EXTEND Gram
695 GLOBAL: gallina_ext module_expr module_type section_subset_expr;
696
697 gallina_ext:
698 [ [ (* Interactive module declaration *)
699 IDENT "Module"; export = export_token; id = identref;
700 bl = LIST0 module_binder; sign = of_module_type;
701 body = is_module_expr ->
702 { VernacSynterp (VernacDefineModule (export, id, bl, sign, body)) }
703 | IDENT "Module"; "Type"; id = identref;
704 bl = LIST0 module_binder; sign = check_module_types;
705 body = is_module_type ->
706 { VernacSynterp (VernacDeclareModuleType (id, bl, sign, body)) }
707 | IDENT "Declare"; IDENT "Module"; export = export_token; id = identref;
708 bl = LIST0 module_binder; ":"; mty = module_type_inl ->
709 { VernacSynterp (VernacDeclareModule (export, id, bl, mty)) }
710 (* Section beginning *)
711 | IDENT "Section"; id = identref -> { VernacSynterp (VernacBeginSection id) }
712
713 (* This end a Section a Module or a Module Type *)
714 | IDENT "End"; id = identref -> { VernacSynterp (VernacEndSegment id) }
715
716 (* Naming a set of section hyps *)
717 | IDENT "Collection"; id = identref; ":="; expr = section_subset_expr ->
718 { VernacSynPure (VernacNameSectionHypSet (id, expr)) }
719
720 (* Requiring an external file *)
721 | IDENT "From" ; ns = global ;
722 IDENT "Extra"; IDENT "Dependency"; f = ne_string ;
723 id = OPT [ "as"; id = IDENT -> { id } ] ->
724 { VernacSynterp (VernacExtraDependency (ns, f, Option.map Id.of_string id)) }
725
726 (* Requiring an already compiled module *)
727 | IDENT "Require"; export = export_token; qidl = LIST1 filtered_import ->
728 { VernacSynterp (VernacRequire (None, export, qidl)) }
729 | IDENT "From" ; ns = global ; IDENT "Require"; export = export_token
730 ; qidl = LIST1 filtered_import ->
731 { VernacSynterp (VernacRequire (Some ns, export, qidl)) }
732 | IDENT "Import"; cats = OPT import_categories; qidl = LIST1 filtered_import ->
733 { VernacSynterp (VernacImport ((Import,cats),qidl)) }
734 | IDENT "Export"; cats = OPT import_categories; qidl = LIST1 filtered_import ->
735 { VernacSynterp (VernacImport ((Export,cats),qidl)) }
736 | IDENT "Include"; e = module_type_inl; l = LIST0 ext_module_type ->
737 { VernacSynterp (VernacInclude(e::l)) }
738 | IDENT "Include"; "Type"; e = module_type_inl; l = LIST0 ext_module_type ->
739 { warn_deprecated_include_type ~loc ();
740 VernacSynterp (VernacInclude(e::l)) } ] ]
741 ;
742 import_categories:
743 [ [ negative = OPT "-"; "("; cats = LIST1 qualid SEP ","; ")" ->
744 { let cats = List.map (fun cat -> CAst.make ?loc:cat.CAst.loc (Libnames.string_of_qualid cat)) cats in
745 { negative=Option.has_some negative; import_cats = cats } }
746 ] ]
747 ;
748 filtered_import:
749 [ [ m = global -> { (m, ImportAll) }
750 | m = global; "("; ns = LIST1 one_import_filter_name SEP ","; ")" -> { (m, ImportNames ns) } ] ]
751 ;
752 one_import_filter_name:
753 [ [ n = global; etc = OPT [ "("; ".."; ")" -> { () } ] -> { n, Option.has_some etc } ] ]
754 ;
755 export_token:
756 [ [ IDENT "Import"; cats = OPT import_categories -> { Some (Import,cats) }
757 | IDENT "Export"; cats = OPT import_categories -> { Some (Export,cats) }
758 | -> { None } ] ]
759 ;
760 ext_module_type:
761 [ [ "<+"; mty = module_type_inl -> { mty } ] ]
762 ;
763 ext_module_expr:
764 [ [ "<+"; mexpr = module_expr_inl -> { mexpr } ] ]
765 ;
766 check_module_type:
767 [ [ "<:"; mty = module_type_inl -> { mty } ] ]
768 ;
769 check_module_types:
770 [ [ mtys = LIST0 check_module_type -> { mtys } ] ]
771 ;
772 of_module_type:
773 [ [ ":"; mty = module_type_inl -> { Enforce mty }
774 | mtys = check_module_types -> { Check mtys } ] ]
775 ;
776 is_module_type:
777 [ [ ":="; mty = module_type_inl ; l = LIST0 ext_module_type -> { (mty::l) }
778 | -> { [] } ] ]
779 ;
780 is_module_expr:
781 [ [ ":="; mexpr = module_expr_inl; l = LIST0 ext_module_expr -> { (mexpr::l) }
782 | -> { [] } ] ]
783 ;
784 functor_app_annot:
785 [ [ "["; IDENT "inline"; "at"; IDENT "level"; i = natural; "]" ->
786 { InlineAt i }
787 | "["; IDENT "no"; IDENT "inline"; "]" -> { NoInline }
788 | -> { DefaultInline }
789 ] ]
790 ;
791 module_expr_inl:
792 [ [ "!"; me = module_expr -> { (me,NoInline) }
793 | me = module_expr; a = functor_app_annot -> { (me,a) } ] ]
794 ;
795 module_type_inl:
796 [ [ "!"; me = module_type -> { (me,NoInline) }
797 | me = module_type; a = functor_app_annot -> { (me,a) } ] ]
798 ;
799 (* Module binder *)
800 module_binder:
801 [ [ "("; export = export_token; idl = LIST1 identref; ":";
802 mty = module_type_inl; ")" -> { (export,idl,mty) } ] ]
803 ;
804 (* Module expressions *)
805 module_expr:
806 [ [ me = module_expr_atom -> { CAst.make ~loc @@ CMident me }
807 | me1 = module_expr; me2 = module_expr_atom -> { CAst.make ~loc @@ CMapply (me1,me2) }
808 ] ]
809 ;
810 module_expr_atom:
811 [ [ qid = qualid -> { qid } | "("; me = module_expr_atom; ")" -> { me } ] ]
812 ;
813 with_declaration:
814 [ [ "Definition"; fqid = fullyqualid; udecl = OPT univ_decl; ":="; c = Constr.lconstr ->
815 { CWith_Definition (fqid,udecl,c) }
816 | IDENT "Module"; fqid = fullyqualid; ":="; qid = qualid ->
817 { CWith_Module (fqid,qid) }
818 ] ]
819 ;
820 module_type:
821 [ [ qid = qualid -> { CAst.make ~loc @@ CMident qid }
822 | "("; mt = module_type; ")" -> { mt }
823 | mty = module_type; me = module_expr_atom ->
824 { CAst.make ~loc @@ CMapply (mty,me) }
825 | mty = module_type; "with"; decl = with_declaration ->
826 { CAst.make ~loc @@ CMwith (mty,decl) }
827 ] ]
828 ;
829 (* Proof using *)
830 section_subset_expr:
831 [ [ test_only_starredidentrefs; l = LIST0 starredidentref ->
832 { starredidentreflist_to_expr l }
833 | e = ssexpr -> { e } ]]
834 ;
835 starredidentref:
836 [ [ i = identref -> { SsSingl i }
837 | i = identref; "*" -> { SsFwdClose(SsSingl i) }
838 | "Type" -> { SsType }
839 | "Type"; "*" -> { SsFwdClose SsType } ]]
840 ;
841 ssexpr:
842 [ "35"
843 [ "-"; e = ssexpr -> { SsCompl e } ]
844 | "50"
845 [ e1 = ssexpr; "-"; e2 = ssexpr-> { SsSubstr(e1,e2) }
846 | e1 = ssexpr; "+"; e2 = ssexpr-> { SsUnion(e1,e2) } ]
847 | "0"
848 [ i = starredidentref -> { i }
849 | "()" -> { SsEmpty }
850 | "("; test_only_starredidentrefs; l = LIST0 starredidentref; ")"->
851 { starredidentreflist_to_expr l }
852 | "("; test_only_starredidentrefs; l = LIST0 starredidentref; ")"; "*" ->
853 { SsFwdClose(starredidentreflist_to_expr l) }
854 | "("; e = ssexpr; ")"-> { e }
855 | "("; e = ssexpr; ")"; "*" -> { SsFwdClose e } ] ]
856 ;
857 END
858
859 (* Extensions: implicits, coercions, etc. *)
860 GRAMMAR EXTEND Gram
861 GLOBAL: gallina_ext hint_info scope_delimiter;
862
863 gallina_ext: TOP
864 [ [ (* Transparent and Opaque *)
865 IDENT "Transparent"; o = OPT [ "!" -> {()} ]; l = LIST1 smart_global ->
866 { VernacSynPure (VernacSetOpacity ((Conv_oracle.transparent, l), o <> None)) }
867 | IDENT "Opaque"; o = OPT [ "!" -> {()} ]; l = LIST1 smart_global ->
868 { VernacSynPure (VernacSetOpacity ((Conv_oracle.Opaque, l), o <> None)) }
869 | IDENT "Strategy"; l =
870 LIST1 [ v=strategy_level; "["; q=LIST1 smart_global; "]" -> { (v,q) } ] ->
871 { VernacSynPure (VernacSetStrategy l) }
872 (* Canonical structure *)
873 | IDENT "Canonical"; OPT [ IDENT "Structure" -> {()} ]; qid = global; ud = OPT [ u = OPT univ_decl; d = def_body -> { (u,d) } ] ->
874 { match ud with
875 | None ->
876 VernacSynPure (VernacCanonical CAst.(make ?loc:qid.CAst.loc @@ AN qid))
877 | Some (u,d) ->
878 let s = coerce_reference_to_id qid in
879 VernacSynPure (VernacDefinition ((NoDischarge,CanonicalStructure),((CAst.make ?loc:qid.CAst.loc (Name s)),u),d)) }
880 | IDENT "Canonical"; OPT [ IDENT "Structure" -> {()} ]; ntn = by_notation ->
881 { VernacSynPure (VernacCanonical CAst.(make ~loc @@ ByNotation ntn)) }
882
883 (* Coercions *)
884 | IDENT "Coercion"; qid = global; ud = OPT [ u = OPT univ_decl; d = def_body -> { u, d } ] ->
885 { match ud with Some (u, d) -> let s = coerce_reference_to_id qid in
886 VernacSynPure (VernacDefinition ((NoDischarge,Coercion),((CAst.make ?loc:qid.CAst.loc (Name s)),u),d))
887 | None -> VernacSynPure (VernacCoercion (CAst.make ~loc @@ AN qid, None)) }
888 | IDENT "Identity"; IDENT "Coercion"; f = identref; ":";
889 s = coercion_class; ">->"; t = coercion_class ->
890 { VernacSynPure (VernacIdentityCoercion (f, s, t)) }
891 | IDENT "Coercion"; qid = global; ":"; s = coercion_class; ">->";
892 t = coercion_class ->
893 { VernacSynPure (VernacCoercion (CAst.make ~loc @@ AN qid, Some(s, t))) }
894 | IDENT "Coercion"; ntn = by_notation; ":"; s = coercion_class; ">->";
895 t = coercion_class ->
896 { VernacSynPure (VernacCoercion (CAst.make ~loc @@ ByNotation ntn, Some (s, t))) }
897
898 | IDENT "Context"; c = LIST1 binder ->
899 { VernacSynPure (VernacContext (List.flatten c)) }
900
901 | IDENT "Instance"; namesup = instance_name; ":";
902 t = term LEVEL "200";
903 info = hint_info ;
904 props = [ ":="; "{"; r = record_declaration; "}" -> { Some (true,r) } |
905 ":="; c = lconstr -> { Some (false,c) } | -> { None } ] ->
906 { VernacSynPure (VernacInstance (fst namesup,snd namesup,t,props,info)) }
907
908 | IDENT "Existing"; IDENT "Instance"; id = global;
909 info = hint_info ->
910 { VernacSynPure (VernacExistingInstance [id, info]) }
911
912 | IDENT "Existing"; IDENT "Instances"; ids = LIST1 global;
913 pri = OPT [ "|"; i = natural -> { i } ] ->
914 { let info = { Typeclasses.hint_priority = pri; hint_pattern = None } in
915 let insts = List.map (fun i -> (i, info)) ids in
916 VernacSynPure (VernacExistingInstance insts) }
917
918 | IDENT "Existing"; IDENT "Class"; is = global -> { VernacSynPure (VernacExistingClass is) }
919
920 (* Arguments *)
921 | IDENT "Arguments"; qid = smart_global;
922 args = LIST0 arg_specs;
923 more_implicits = OPT
924 [ ","; impl = LIST1
925 [ impl = LIST0 implicits_alt -> { List.flatten impl } ]
926 SEP "," -> { impl }
927 ];
928 mods = OPT [ ":"; l = LIST1 args_modifier SEP "," -> { l } ] ->
929 { let mods = match mods with None -> [] | Some l -> List.flatten l in
930 let more_implicits = Option.default [] more_implicits in
931 VernacSynPure (VernacArguments (qid, List.flatten args, more_implicits, mods)) }
932
933 | IDENT "Implicit"; "Type"; bl = reserv_list ->
934 { VernacSynPure (VernacReserve bl) }
935
936 | IDENT "Implicit"; IDENT "Types"; bl = reserv_list ->
937 { test_plural_form_types loc "Implicit Types" bl;
938 VernacSynPure (VernacReserve bl) }
939
940 | IDENT "Generalizable";
941 gen = [IDENT "All"; IDENT "Variables" -> { Some [] }
942 | IDENT "No"; IDENT "Variables" -> { None }
943 | ["Variable" -> { () } | IDENT "Variables" -> { () } ];
944 idl = LIST1 identref -> { Some idl } ] ->
945 { VernacSynPure (VernacGeneralizable gen) } ] ]
946 ;
947 args_modifier:
948 [ [ IDENT "simpl"; IDENT "nomatch" -> { [`SimplDontExposeCase] }
949 | IDENT "simpl"; IDENT "never" -> { [`SimplNeverUnfold] }
950 | IDENT "clear"; IDENT "simpl" -> { [`ClearReduction] }
951 | IDENT "default"; IDENT "implicits" -> { [`DefaultImplicits] }
952 | IDENT "clear"; IDENT "implicits" -> { [`ClearImplicits] }
953 | IDENT "clear"; IDENT "scopes" -> { [`ClearScopes] }
954 | IDENT "clear"; IDENT "bidirectionality"; IDENT "hint" -> { [`ClearBidiHint] }
955 | IDENT "rename" -> { [`Rename] }
956 | IDENT "assert" -> { [`Assert] }
957 | IDENT "extra"; IDENT "scopes" -> { [`ExtraScopes] }
958 | IDENT "clear"; IDENT "scopes"; IDENT "and"; IDENT "implicits" ->
959 { [`ClearImplicits; `ClearScopes] }
960 | IDENT "clear"; IDENT "implicits"; IDENT "and"; IDENT "scopes" ->
961 { [`ClearImplicits; `ClearScopes] }
962 ] ]
963 ;
964 scope_delimiter:
965 [ [ "%"; key = IDENT -> { DelimUnboundedScope, key }
966 | "%_"; key = IDENT -> { DelimOnlyTmpScope, key } ] ]
967 ;
968 argument_spec: [
969 [ b = OPT "!"; id = name ; s = LIST0 scope_delimiter ->
970 { id.CAst.v, not (Option.is_empty b), List.map (fun x -> CAst.make ~loc x) s }
971 ]
972 ];
973 (* List of arguments implicit status, scope, modifiers *)
974 arg_specs: [
975 [ item = argument_spec ->
976 { let name, recarg_like, notation_scope = item in
977 [RealArg { name=name; recarg_like=recarg_like;
978 notation_scope=notation_scope;
979 implicit_status = Explicit}] }
980 | "/" -> { [VolatileArg] }
981 | "&" -> { [BidiArg] }
982 | "("; items = LIST1 argument_spec; ")"; scl = LIST0 scope_delimiter ->
983 { let scl = List.map (CAst.make ~loc) scl in
984 List.map (fun (name,recarg_like,notation_scope) ->
985 RealArg { name=name; recarg_like=recarg_like;
986 notation_scope = notation_scope @ scl;
987 implicit_status = Explicit}) items }
988 | "["; items = LIST1 argument_spec; "]"; scl = LIST0 scope_delimiter ->
989 { let scl = List.map (CAst.make ~loc) scl in
990 List.map (fun (name,recarg_like,notation_scope) ->
991 RealArg { name=name; recarg_like=recarg_like;
992 notation_scope = notation_scope @ scl;
993 implicit_status = NonMaxImplicit}) items }
994 | "{"; items = LIST1 argument_spec; "}"; scl = LIST0 scope_delimiter ->
995 { let scl = List.map (CAst.make ~loc) scl in
996 List.map (fun (name,recarg_like,notation_scope) ->
997 RealArg { name=name; recarg_like=recarg_like;
998 notation_scope = notation_scope @ scl;
999 implicit_status = MaxImplicit}) items }
1000 ]
1001 ];
1002 (* Same as [arg_specs], but with only implicit status and names *)
1003 implicits_alt: [
1004 [ name = name -> { [(name.CAst.v, Explicit)] }
1005 | "["; items = LIST1 name; "]" ->
1006 { List.map (fun name -> (name.CAst.v, NonMaxImplicit)) items }
1007 | "{"; items = LIST1 name; "}" ->
1008 { List.map (fun name -> (name.CAst.v, MaxImplicit)) items }
1009 ]
1010 ];
1011 instance_name:
1012 [ [ name = ident_decl; bl = binders ->
1013 { (CAst.map (fun id -> Name id) (fst name), snd name), bl }
1014 | -> { ((CAst.make ~loc Anonymous), None), [] } ] ]
1015 ;
1016 hint_info:
1017 [ [ "|"; i = OPT natural; pat = OPT constr_pattern ->
1018 { { Typeclasses.hint_priority = i; hint_pattern = pat } }
1019 | -> { { Typeclasses.hint_priority = None; hint_pattern = None } } ] ]
1020 ;
1021 reserv_list:
1022 [ [ bl = LIST1 reserv_tuple -> { bl } | b = simple_reserv -> { [b] } ] ]
1023 ;
1024 reserv_tuple:
1025 [ [ "("; a = simple_reserv; ")" -> { a } ] ]
1026 ;
1027 simple_reserv:
1028 [ [ idl = LIST1 identref; ":"; c = lconstr -> { (idl,c) } ] ]
1029 ;
1030
1031 END
1032
1033 {
1034
1035 (* Hack to parse "[ id" without dropping [ *)
1036 let test_bracket_ident =
1037 let open Procq.Lookahead in
1038 to_entry "test_bracket_ident" begin
1039 lk_kw "[" >> lk_ident
1040 end
1041
1042 }
1043
1044 GRAMMAR EXTEND Gram
1045 GLOBAL: toplevel_selector goal_selector;
1046 range_selector:
1047 [ [ n = natural ; "-" ; m = natural -> { Proofview.RangeSelector (n, m) }
1048 | n = natural -> { Proofview.NthSelector n }
1049 | test_bracket_ident; "["; id = qualid; "]" -> { Proofview.IdSelector id } ] ]
1050 ;
1051 goal_selector:
1052 [ [ l = LIST1 range_selector SEP "," -> { Goal_select.SelectList l } ] ]
1053 ;
1054 toplevel_selector:
1055 [ [ sel = goal_selector; ":" -> { sel }
1056 | "!"; ":" -> { Goal_select.SelectAlreadyFocused }
1057 | IDENT "all"; ":" -> { Goal_select.SelectAll } ] ]
1058 ;
1059 END
1060
1061 GRAMMAR EXTEND Gram
1062 GLOBAL: command query_command coercion_class gallina_ext search_query search_queries;
1063
1064 gallina_ext: TOP
1065 [ [ IDENT "Export"; "Set"; table = setting_name; v = option_setting ->
1066 { VernacSynterp (VernacSetOption (true, table, v)) }
1067 | IDENT "Export"; IDENT "Unset"; table = setting_name ->
1068 { VernacSynterp (VernacSetOption (true, table, OptionUnset)) }
1069 ] ];
1070
1071 command:
1072 [ [ IDENT "Comments"; l = LIST0 comment -> { VernacSynPure (VernacComments l) }
1073
1074 | IDENT "Attributes"; attr = attribute_list ->
1075 { VernacSynPure (VernacAttributes attr) }
1076
1077 (* Hack! Should be in grammar_ext, but camlp5 factorizes badly *)
1078 | IDENT "Declare"; IDENT "Instance"; id = ident_decl; bl = binders; ":";
1079 t = term LEVEL "200";
1080 info = hint_info ->
1081 { VernacSynPure (VernacDeclareInstance (id, bl, t, info)) }
1082
1083 (* Should be in syntax, but camlp5 would not factorize *)
1084 | IDENT "Declare"; IDENT "Scope"; sc = IDENT ->
1085 { VernacSynPure (VernacDeclareScope sc) }
1086
1087 (* System directory *)
1088 | IDENT "Pwd" -> { VernacSynterp (VernacChdir None) }
1089 | IDENT "Cd" -> { warn_chdir_pwd (); VernacSynterp (VernacChdir None) }
1090 | IDENT "Cd"; dir = ne_string -> { VernacSynterp (VernacChdir (Some dir)) }
1091
1092 | IDENT "Load"; verbosely = [ IDENT "Verbose" -> { true } | -> { false } ];
1093 s = [ s = ne_string -> { s } | s = IDENT -> { s } ] ->
1094 { VernacSynterp (VernacLoad (verbosely, s)) }
1095 | IDENT "Declare"; IDENT "ML"; IDENT "Module"; l = LIST1 ne_string ->
1096 { VernacSynterp (VernacDeclareMLModule l) }
1097
1098 | IDENT "Locate"; l = locatable -> { VernacSynPure (VernacLocate l) }
1099
1100 (* Type-Checking *)
1101 | "Type"; c = lconstr -> { VernacSynPure (VernacGlobalCheck c) }
1102
1103 (* Printing (careful factorization of entries) *)
1104 | IDENT "Print"; p = printable -> { VernacSynPure (VernacPrint p) }
1105 | IDENT "Print"; qid = smart_global; l = OPT univ_name_list -> { VernacSynPure (VernacPrint (PrintName (qid,l))) }
1106 | IDENT "Print"; IDENT "Module"; "Type"; qid = global ->
1107 { VernacSynPure (VernacPrint (PrintModuleType qid)) }
1108 | IDENT "Print"; IDENT "Module"; qid = global ->
1109 { VernacSynPure (VernacPrint (PrintModule qid)) }
1110 | IDENT "Print"; IDENT "Namespace" ; ns = dirpath ->
1111 { VernacSynPure (VernacPrint (PrintNamespace ns)) }
1112 | IDENT "Inspect"; n = natural -> { VernacSynPure (VernacPrint (PrintInspect n)) }
1113
1114 (* For acting on parameter tables *)
1115 | "Set"; table = setting_name; v = option_setting ->
1116 { VernacSynterp (VernacSetOption (false, table, v)) }
1117 | IDENT "Unset"; table = setting_name ->
1118 { VernacSynterp (VernacSetOption (false, table, OptionUnset)) }
1119
1120 | IDENT "Print"; IDENT "Table"; table = setting_name ->
1121 { VernacSynPure (VernacPrintOption table) }
1122
1123 | IDENT "Add"; table = IDENT; field = IDENT; v = LIST1 table_value
1124 -> { VernacSynPure (VernacAddOption ([table;field], v)) }
1125 (* A global value below will be hidden by a field above! *)
1126 (* In fact, we give priority to secondary tables *)
1127 (* No syntax for tertiary tables due to conflict *)
1128 (* (but they are unused anyway) *)
1129 | IDENT "Add"; table = IDENT; v = LIST1 table_value ->
1130 { VernacSynPure (VernacAddOption ([table], v)) }
1131
1132 | IDENT "Test"; table = setting_name; "for"; v = LIST1 table_value
1133 -> { VernacSynPure (VernacMemOption (table, v)) }
1134 | IDENT "Test"; table = setting_name ->
1135 { VernacSynPure (VernacPrintOption table) }
1136
1137 | IDENT "Remove"; table = IDENT; field = IDENT; v= LIST1 table_value
1138 -> { VernacSynPure (VernacRemoveOption ([table;field], v)) }
1139 | IDENT "Remove"; table = IDENT; v = LIST1 table_value ->
1140 { VernacSynPure (VernacRemoveOption ([table], v)) } ]]
1141 ;
1142 query_command:
1143 [ [ IDENT "Eval"; r = red_expr; "in"; c = lconstr; "." ->
1144 { fun g -> VernacCheckMayEval (Some r, g, c) }
1145 | IDENT "Compute"; c = lconstr; "." ->
1146 { fun g -> VernacCheckMayEval (Some (Genredexpr.CbvVm None), g, c) }
1147 | IDENT "Check"; c = lconstr; "." ->
1148 { fun g -> VernacCheckMayEval (None, g, c) }
1149 (* Searching the environment *)
1150 | IDENT "About"; qid = smart_global; l = OPT univ_name_list; "." ->
1151 { fun g -> VernacPrint (PrintAbout (qid,l,g)) }
1152 | IDENT "SearchPattern"; c = constr_pattern; l = in_or_out_modules; "." ->
1153 { fun g -> VernacSearch (SearchPattern c,g, l) }
1154 | IDENT "SearchRewrite"; c = constr_pattern; l = in_or_out_modules; "." ->
1155 { fun g -> VernacSearch (SearchRewrite c,g, l) }
1156 | IDENT "Search"; s = search_query; l = search_queries; "." ->
1157 { let (sl,m) = l in fun g -> VernacSearch (Search (s::sl),g, m) }
1158 ] ]
1159 ;
1160 printable:
1161 [ [ IDENT "Term"; qid = smart_global; l = OPT univ_name_list -> { PrintName (qid,l) }
1162 | IDENT "All" -> { PrintFullContext }
1163 | IDENT "Section"; s = global -> { PrintSectionContext s }
1164 | IDENT "Grammar"; ents = LIST0 IDENT ->
1165 (* This should be in "syntax" section but is here for factorization*)
1166 { PrintGrammar ents }
1167 | IDENT "Custom"; IDENT "Grammar"; ent = qualid ->
1168 (* Should also be in "syntax" section *)
1169 { PrintCustomGrammar ent }
1170 | IDENT "Keywords" ->
1171 { PrintKeywords }
1172 | IDENT "LoadPath"; dir = OPT dirpath -> { PrintLoadPath dir }
1173 | IDENT "Libraries" -> { PrintLibraries }
1174
1175 | IDENT "Notation"; ntn = string ->
1176 { PrintNotation (Constrexpr.InConstrEntry, ntn) }
1177 | IDENT "Notation"; ntn = string; IDENT "in"; IDENT "custom"; ent = qualid ->
1178 { PrintNotation (Constrexpr.InCustomEntry ent, ntn) }
1179
1180 | IDENT "ML"; IDENT "Path" -> { PrintMLLoadPath }
1181 | IDENT "ML"; IDENT "Modules" -> { PrintMLModules }
1182 | IDENT "Debug"; IDENT "GC" -> { PrintDebugGC }
1183 | IDENT "Graph" -> { PrintGraph }
1184 | IDENT "Classes" -> { PrintClasses }
1185 | IDENT "Typeclasses" -> { PrintTypeclasses }
1186 | IDENT "Instances"; qid = smart_global -> { PrintInstances qid }
1187 | IDENT "Coercions" -> { PrintCoercions }
1188 | IDENT "Coercion"; IDENT "Paths"; s = coercion_class; t = coercion_class ->
1189 { PrintCoercionPaths (s,t) }
1190 | IDENT "Canonical"; IDENT "Projections"; qids = LIST0 smart_global ->
1191 { PrintCanonicalConversions qids }
1192 | IDENT "Typing"; IDENT "Flags" -> { PrintTypingFlags }
1193 | IDENT "Tables" -> { PrintTables }
1194 | IDENT "Options" -> { PrintTables (* A Synonymous to Tables *) }
1195 | IDENT "Hint" -> { PrintHintGoal }
1196 | IDENT "Hint"; qid = smart_global -> { PrintHint qid }
1197 | IDENT "Hint"; "*" -> { PrintHintDb }
1198 | IDENT "HintDb"; s = IDENT -> { PrintHintDbName s }
1199 | IDENT "Scopes" -> { PrintScopes }
1200 | IDENT "Scope"; s = IDENT -> { PrintScope s }
1201 | IDENT "Visibility"; s = OPT IDENT -> { PrintVisibility s }
1202 | IDENT "Implicit"; qid = smart_global -> { PrintImplicit qid }
1203 | b = [ IDENT "Sorted" -> { true } | -> { false } ]; IDENT "Universes";
1204 g = OPT printunivs_subgraph;
1205 with_sources = OPT [
1206 b = [ IDENT "With" -> { true } | IDENT "Without" -> { false } ];
1207 IDENT "Constraint"; IDENT "Sources" -> { b } ];
1208 fopt = OPT ne_string ->
1209 { PrintUniverses {sort=b; subgraph=g; with_sources; file=fopt;} }
1210 | IDENT "Sorts" -> { PrintSorts }
1211 | IDENT "Assumptions"; qids = LIST1 smart_global -> { PrintAssumptions (false, false, qids) }
1212 | IDENT "Opaque"; IDENT "Dependencies"; qids = LIST1 smart_global -> { PrintAssumptions (true, false, qids) }
1213 | IDENT "Transparent"; IDENT "Dependencies"; qids = LIST1 smart_global -> { PrintAssumptions (false, true, qids) }
1214 | IDENT "All"; IDENT "Dependencies"; qids = LIST1 smart_global -> { PrintAssumptions (true, true, qids) }
1215 | IDENT "Strategy"; qid = smart_global -> { PrintStrategy (Some qid) }
1216 | IDENT "Strategies" -> { PrintStrategy None }
1217 | IDENT "Registered" -> { PrintRegistered }
1218 | IDENT "Registered"; IDENT "Schemes" -> { PrintRegisteredSchemes }
1219 ] ]
1220 ;
1221 debug_univ_name:
1222 [ [ x = reference -> { NamedUniv x }
1223 | x = STRING -> { RawUniv (CAst.make ~loc x) }
1224 ] ]
1225 ;
1226 printunivs_subgraph:
1227 [ [ IDENT "Subgraph"; "("; l = LIST0 debug_univ_name; ")" -> { l } ] ]
1228 ;
1229 coercion_class:
1230 [ [ IDENT "Funclass" -> { FunClass }
1231 | IDENT "Sortclass" -> { SortClass }
1232 | qid = smart_global -> { RefClass qid } ] ]
1233 ;
1234 locatable:
1235 [ [ qid = smart_global -> { LocateAny qid }
1236 | IDENT "Term"; qid = smart_global -> { LocateTerm qid }
1237 | IDENT "File"; f = ne_string -> { LocateFile f }
1238 | IDENT "Library"; qid = global -> { LocateLibrary qid }
1239 | IDENT "Module"; qid = global -> { LocateModule qid } ] ]
1240 ;
1241 option_setting:
1242 [ [ -> { OptionSetTrue }
1243 | n = integer -> { OptionSetInt n }
1244 | s = STRING -> { OptionSetString s } ] ]
1245 ;
1246 table_value:
1247 [ [ id = global -> { Goptions.QualidRefValue id }
1248 | s = STRING -> { Goptions.StringRefValue s } ] ]
1249 ;
1250 setting_name:
1251 [ [ fl = LIST1 [ x = IDENT -> { x } ] -> { fl } ]]
1252 ;
1253 ne_in_or_out_modules:
1254 [ [ IDENT "inside"; l = LIST1 global -> { SearchInside l }
1255 | "in"; l = LIST1 global -> { SearchInside l }
1256 | IDENT "outside"; l = LIST1 global -> { SearchOutside l } ] ]
1257 ;
1258 in_or_out_modules:
1259 [ [ m = ne_in_or_out_modules -> { m }
1260 | -> { SearchOutside [] } ] ]
1261 ;
1262 comment:
1263 [ [ c = constr -> { CommentConstr c }
1264 | s = STRING -> { CommentString s }
1265 | n = natural -> { CommentInt n } ] ]
1266 ;
1267 positive_search_mark:
1268 [ [ "-" -> { false } | -> { true } ] ]
1269 ;
1270 search_query:
1271 [ [ b = positive_search_mark; s = search_item -> { (b, SearchLiteral s) }
1272 | b = positive_search_mark; "["; l = LIST1 (LIST1 search_query) SEP "|"; "]" -> { (b, SearchDisjConj l) }
1273 ] ]
1274 ;
1275 search_item:
1276 [ [ test_id_colon; where = search_where; ":"; s = ne_string; sc = OPT scope_delimiter ->
1277 { SearchString (where,s,sc) }
1278 | IDENT "is"; ":"; kl = logical_kind ->
1279 { SearchKind kl }
1280 | s = ne_string; sc = OPT scope_delimiter ->
1281 { SearchString ((Anywhere,false),s,sc) }
1282 | test_id_colon; where = search_where; ":"; p = constr_pattern ->
1283 { SearchSubPattern (where,p) }
1284 | p = constr_pattern ->
1285 { SearchSubPattern ((Anywhere,false),p) }
1286 ] ]
1287 ;
1288 logical_kind:
1289 [ [ k = thm_token -> { IsProof k }
1290 | k = assumption_token -> { IsAssumption (snd k) }
1291 | k = IDENT "Context" -> { IsAssumption Context }
1292 | k = extended_def_token -> { IsDefinition k }
1293 | IDENT "Primitive" -> { IsPrimitive }
1294 | IDENT "Symbol" -> { IsSymbol } ] ]
1295 ;
1296 extended_def_token:
1297 [ [ k = def_token -> { snd k }
1298 | IDENT "Coercion" -> { Coercion }
1299 | IDENT "Fixpoint" -> { Fixpoint }
1300 | IDENT "CoFixpoint" -> { CoFixpoint }
1301 | IDENT "Instance" -> { Instance }
1302 | IDENT "Scheme" -> { Scheme }
1303 | IDENT "Canonical" -> { CanonicalStructure }
1304 | IDENT "Field" -> { StructureComponent }
1305 | IDENT "Method" -> { Method } ] ]
1306 ;
1307 search_where:
1308 [ [ IDENT "head" -> { Anywhere, true }
1309 | IDENT "hyp" -> { InHyp, false }
1310 | IDENT "concl" -> { InConcl, false }
1311 | IDENT "headhyp" -> { InHyp, true }
1312 | IDENT "headconcl" -> { InConcl, true } ] ]
1313 ;
1314 search_queries:
1315 [ RIGHTA [ m = ne_in_or_out_modules -> { ([],m) }
1316 | s = search_query; l = search_queries ->
1317 { let (sl,m) = l in (s::sl,m) }
1318 | -> { ([],SearchOutside []) }
1319 ] ]
1320 ;
1321 univ_name_list:
1322 [ [ "@{" ; l = LIST0 name; "}" -> { [],l } ] ]
1323 ;
1324 END
1325
1326 GRAMMAR EXTEND Gram
1327 GLOBAL: command;
1328
1329 command: TOP
1330 [ [
1331 (* Resetting *)
1332 IDENT "Reset"; IDENT "Initial" -> { VernacSynPure (VernacResetInitial) }
1333 | IDENT "Reset"; id = identref -> { VernacSynPure (VernacResetName id) }
1334 | IDENT "Back" -> { VernacSynPure (VernacBack 1) }
1335 | IDENT "Back"; n = natural -> { VernacSynPure (VernacBack n) }
1336
1337 (* Tactic Debugger *)
1338 | IDENT "Debug"; IDENT "On" ->
1339 { VernacSynterp (VernacSetOption (false, ["Ltac";"Debug"], OptionSetTrue)) }
1340
1341 | IDENT "Debug"; IDENT "Off" ->
1342 { VernacSynterp (VernacSetOption (false, ["Ltac";"Debug"], OptionUnset)) }
1343
1344 (* registration of a custom reduction *)
1345
1346 | IDENT "Declare"; IDENT "Reduction"; s = IDENT; ":=";
1347 r = red_expr ->
1348 { VernacSynPure (VernacDeclareReduction (s,r)) }
1349
1350 (* factorized here, though relevant for syntax extensions *)
1351
1352 | IDENT "Declare"; IDENT "Custom"; IDENT "Entry"; s = ident ->
1353 { VernacSynterp (VernacDeclareCustomEntry s) }
1354
1355 ] ];
1356 END
1357
1358 (* Grammar extensions *)
1359
1360 GRAMMAR EXTEND Gram
1361 GLOBAL: syntax syntax_modifiers;
1362
1363 syntax:
1364 [ [ IDENT "Open"; IDENT "Scope"; sc = IDENT ->
1365 { VernacSynPure (VernacOpenCloseScope (true,sc)) }
1366
1367 | IDENT "Close"; IDENT "Scope"; sc = IDENT ->
1368 { VernacSynPure (VernacOpenCloseScope (false,sc)) }
1369
1370 | IDENT "Delimit"; IDENT "Scope"; sc = IDENT; "with"; key = IDENT ->
1371 { VernacSynPure(VernacDelimiters (sc, Some key)) }
1372 | IDENT "Undelimit"; IDENT "Scope"; sc = IDENT ->
1373 { VernacSynPure(VernacDelimiters (sc, None)) }
1374
1375 | IDENT "Bind"; IDENT "Scope"; sc = IDENT; "with";
1376 refl = LIST1 coercion_class -> { VernacSynPure (VernacBindScope (sc,refl)) }
1377
1378 | IDENT "Infix"; ntn_decl = notation_declaration ->
1379 { VernacSynterp (VernacNotation (true,ntn_decl)) }
1380 | lnot = located_notation; id = identref; idl = LIST0 ident;
1381 ":="; c = constr; modl = syntax_modifiers ->
1382 { VernacSynPure (VernacAbbreviation (id,(idl,c), modl, Some lnot)) }
1383 | IDENT "Abbreviation"; id = identref; idl = LIST0 ident;
1384 ":="; c = constr; modl = syntax_modifiers ->
1385 { VernacSynPure (VernacAbbreviation (id,(idl,c), modl, None)) }
1386 | located_notation; ntn_decl = notation_declaration ->
1387 { VernacSynterp (VernacNotation (false,ntn_decl)) }
1388
1389 | IDENT "Reserved"; IDENT "Infix"; s = ne_lstring; l = syntax_modifiers ->
1390 { VernacSynterp (VernacReservedNotation (true,(s,l))) }
1391 | IDENT "Reserved"; IDENT "Notation"; s = ne_lstring; l = syntax_modifiers ->
1392 { VernacSynterp (VernacReservedNotation (false,(s,l))) }
1393
1394 | on = enable_enable_disable; IDENT "Notation";
1395 rule = enable_notation_rule; interp = enable_notation_interpretation;
1396 flags = enable_notation_flags; scope = opt_scope ->
1397 { VernacSynPure (VernacEnableNotation (on, rule, interp, flags, scope)) }
1398
1399 (* "Print" "Grammar" and "Declare" "Scope" should be here but are in "command" entry in order
1400 to factorize with other "Print"-based or "Declare"-based vernac entries *)
1401 ] ]
1402 ;
1403 located_notation:
1404 [ [ IDENT "Notation" -> { loc } ] ]
1405 ;
1406 enable_enable_disable:
1407 [ [ IDENT "Enable" -> { true }
1408 | IDENT "Disable" -> { false } ] ]
1409 ;
1410 enable_notation_rule:
1411 [ [ s = ne_string -> { Some (Inl s) }
1412 | qid = global; idl = LIST0 ident -> { Some (Inr (idl,qid)) }
1413 | -> { None } ] ]
1414 ;
1415 enable_notation_interpretation:
1416 [ [ ":="; c = constr -> { Some c }
1417 | -> { None } ] ]
1418 ;
1419 enable_notation_flags:
1420 [ [ "("; l = LIST1 enable_notation_flag SEP ","; ")" -> { l }
1421 | -> { [] } ] ]
1422 ;
1423 enable_notation_flag:
1424 [ [ IDENT "all" -> { EnableNotationAll }
1425 | IDENT "only"; IDENT "parsing" -> { EnableNotationOnly Notationextern.OnlyParsing }
1426 | IDENT "only"; IDENT "printing" -> { EnableNotationOnly Notationextern.OnlyPrinting }
1427 | "in"; IDENT "custom"; x = qualid -> { EnableNotationEntry (InCustomEntry x) }
1428 | "in"; IDENT "constr" -> { EnableNotationEntry InConstrEntry } ] ]
1429 ;
1430 opt_scope:
1431 [ [ ":"; sc = IDENT -> { Some (NotationInScope sc) }
1432 | ":"; IDENT "no"; IDENT "scope" -> { Some LastLonelyNotation }
1433 | -> { None } ] ]
1434 ;
1435 level:
1436 [ [ IDENT "level"; n = natural -> { NumLevel n }
1437 | IDENT "next"; IDENT "level" -> { NextLevel } ] ]
1438 ;
1439 syntax_modifier:
1440 [ [ "at"; IDENT "level"; n = natural -> { SetLevel n }
1441 | "in"; IDENT "custom"; x = qualid -> { SetCustomEntry (x,None) }
1442 | "in"; IDENT "custom"; x = qualid; "at"; IDENT "level"; n = natural ->
1443 { SetCustomEntry (x,Some n) }
1444 | IDENT "left"; IDENT "associativity" -> { SetAssoc Gramlib.Gramext.LeftA }
1445 | IDENT "right"; IDENT "associativity" -> { SetAssoc Gramlib.Gramext.RightA }
1446 | IDENT "no"; IDENT "associativity" -> { SetAssoc Gramlib.Gramext.NonA }
1447 | IDENT "only"; IDENT "printing" -> { SetOnlyPrinting }
1448 | IDENT "only"; IDENT "parsing" -> { SetOnlyParsing }
1449 | IDENT "format"; s = lstring -> { SetFormat (TextFormat s) }
1450 | x = IDENT; ","; l = LIST1 IDENT SEP ","; v =
1451 [ "at"; lev = level -> { fun x l -> SetItemLevel (x::l,None,lev) }
1452 | "in"; IDENT "scope"; k = IDENT -> { fun x l -> SetItemScope(x::l,k) } ] -> { v x l }
1453 | x = IDENT; "at"; lev = level; b = OPT binder_interp ->
1454 { SetItemLevel ([x],b,lev) }
1455 | x = IDENT; "in"; IDENT "scope"; k = IDENT -> { SetItemScope([x],k) }
1456 | x = IDENT; b = binder_interp -> { SetItemLevel ([x],Some b,DefaultLevel) }
1457 | x = IDENT; typ = explicit_subentry -> { SetEntryType (x,typ) }
1458 ] ]
1459 ;
1460 syntax_modifiers:
1461 [ [ "("; l = LIST1 [ s = syntax_modifier -> { CAst.make ~loc s } ] SEP ","; ")" -> { l }
1462 | -> { [] }
1463 ] ]
1464 ;
1465 explicit_subentry:
1466 [ [ IDENT "ident" -> { ETIdent }
1467 | IDENT "name" -> { ETName }
1468 | IDENT "global" -> { ETGlobal }
1469 | IDENT "bigint" -> { ETBigint }
1470 | IDENT "binder" -> { ETBinder true }
1471 | IDENT "constr" -> { ETConstr (InConstrEntry,None,DefaultLevel) }
1472 | IDENT "constr"; n = at_level_opt; b = OPT binder_interp -> { ETConstr (InConstrEntry,b,n) }
1473 | IDENT "pattern" -> { ETPattern (false,None) }
1474 | IDENT "pattern"; "at"; IDENT "level"; n = natural -> { ETPattern (false,Some n) }
1475 | IDENT "strict"; IDENT "pattern" -> { ETPattern (true,None) }
1476 | IDENT "strict"; IDENT "pattern"; "at"; IDENT "level"; n = natural -> { ETPattern (true,Some n) }
1477 | IDENT "closed"; IDENT "binder" -> { ETBinder false }
1478 | IDENT "custom"; x = qualid; n = at_level_opt; b = OPT binder_interp ->
1479 { ETConstr (InCustomEntry x,b,n) }
1480 ] ]
1481 ;
1482 at_level_opt:
1483 [ [ "at"; n = level -> { n }
1484 | -> { DefaultLevel } ] ]
1485 ;
1486 binder_interp:
1487 [ [ "as"; IDENT "ident" -> { warn_deprecated_as_ident_kind (); Notation_term.AsIdent }
1488 | "as"; IDENT "name" -> { Notation_term.AsName }
1489 | "as"; IDENT "pattern" -> { Notation_term.AsAnyPattern }
1490 | "as"; IDENT "strict"; IDENT "pattern" -> { Notation_term.AsStrictPattern } ] ]
1491 ;
1492 END