1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
|
(************************************************************************)
(* v * The Coq Proof Assistant / The Coq Development Team *)
(* <O___,, * CNRS-Ecole Polytechnique-INRIA Futurs-Universite Paris Sud *)
(* \VV/ **************************************************************)
(* // * This file is distributed under the terms of the *)
(* * GNU Lesser General Public License Version 2.1 *)
(************************************************************************)
(* $Id: g_vernac.ml4 9977 2007-07-12 12:18:46Z msozeau $ *)
(*i camlp4deps: "parsing/grammar.cma" i*)
open Pp
open Util
open Names
open Topconstr
open Vernacexpr
open Pcoq
open Decl_mode
open Tactic
open Decl_kinds
open Genarg
open Extend
open Ppextend
open Goptions
open Prim
open Constr
open Vernac_
open Module
let vernac_kw = [ ";"; ","; ">->"; ":<"; "<:"; "where"; "at" ]
let _ = List.iter (fun s -> Lexer.add_token ("",s)) vernac_kw
(* Rem: do not join the different GEXTEND into one, it breaks native *)
(* compilation on PowerPC and Sun architectures *)
let check_command = Gram.Entry.create "vernac:check_command"
let tactic_mode = Gram.Entry.create "vernac:tactic_command"
let proof_mode = Gram.Entry.create "vernac:proof_command"
let noedit_mode = Gram.Entry.create "vernac:noedit_command"
let class_rawexpr = Gram.Entry.create "vernac:class_rawexpr"
let thm_token = Gram.Entry.create "vernac:thm_token"
let def_body = Gram.Entry.create "vernac:def_body"
let get_command_entry () =
match Decl_mode.get_current_mode () with
Mode_proof -> proof_mode
| Mode_tactic -> tactic_mode
| Mode_none -> noedit_mode
let default_command_entry =
Gram.Entry.of_parser "command_entry"
(fun strm -> Gram.Entry.parse_token (get_command_entry ()) strm)
let no_hook _ _ = ()
GEXTEND Gram
GLOBAL: vernac gallina_ext tactic_mode proof_mode noedit_mode;
vernac:
(* Better to parse "." here: in case of failure (e.g. in coerce_to_var), *)
(* "." is still in the stream and discard_to_dot works correctly *)
[ [ g = gallina; "." -> g
| g = gallina_ext; "." -> g
| c = command; "." -> c
| c = syntax; "." -> c
| "["; l = LIST1 located_vernac; "]"; "." -> VernacList l
] ]
;
vernac: FIRST
[ [ IDENT "Time"; v = vernac -> VernacTime v ] ]
;
vernac: LAST
[ [ prfcom = default_command_entry -> prfcom ] ]
;
noedit_mode:
[ [ c = subgoal_command -> c None] ]
;
tactic_mode:
[ [ gln = OPT[n=natural; ":" -> n];
tac = subgoal_command -> tac gln ] ]
;
subgoal_command:
[ [ c = check_command; "." -> c
| tac = Tactic.tactic;
use_dft_tac = [ "." -> false | "..." -> true ] ->
(fun g ->
let g = match g with Some gl -> gl | _ -> 1 in
VernacSolve(g,tac,use_dft_tac)) ] ]
;
proof_mode:
[ [ instr = proof_instr; "." -> VernacProofInstr instr ] ]
;
proof_mode: LAST
[ [ c=subgoal_command -> c (Some 1) ] ]
;
located_vernac:
[ [ v = vernac -> loc, v ] ]
;
END
let test_plurial_form = function
| [(_,([_],_))] ->
Options.if_verbose warning
"Keywords Variables/Hypotheses/Parameters expect more than one assumption"
| _ -> ()
let no_coercion loc (c,x) =
if c then Util.user_err_loc
(loc,"no_coercion",Pp.str"no coercion allowed here");
x
(* Gallina declarations *)
GEXTEND Gram
GLOBAL: gallina gallina_ext thm_token def_body;
gallina:
(* Definition, Theorem, Variable, Axiom, ... *)
[ [ thm = thm_token; id = identref; bl = LIST0 binder_let; ":";
c = lconstr ->
VernacStartTheoremProof (thm, id, (bl, c), false, no_hook)
| stre = assumption_token; bl = assum_list ->
VernacAssumption (stre, bl)
| stre = assumptions_token; bl = assum_list ->
test_plurial_form bl;
VernacAssumption (stre, bl)
| IDENT "Boxed";"Definition";id = identref; b = def_body ->
VernacDefinition ((Global,true,Definition), id, b, no_hook)
| IDENT "Unboxed";"Definition";id = identref; b = def_body ->
VernacDefinition ((Global,false,Definition), id, b, no_hook)
| (f,d) = def_token; id = identref; b = def_body ->
VernacDefinition (d, id, b, f)
(* Gallina inductive declarations *)
| f = finite_token;
indl = LIST1 inductive_definition SEP "with" ->
VernacInductive (f,indl)
| IDENT "Boxed";"Fixpoint"; recs = LIST1 rec_definition SEP "with" ->
VernacFixpoint (recs,true)
| IDENT "Unboxed";"Fixpoint"; recs = LIST1 rec_definition SEP "with" ->
VernacFixpoint (recs,false)
| "Fixpoint"; recs = LIST1 rec_definition SEP "with" ->
VernacFixpoint (recs,Options.boxed_definitions())
| "CoFixpoint"; corecs = LIST1 corec_definition SEP "with" ->
VernacCoFixpoint (corecs,false)
| IDENT "Scheme"; l = LIST1 scheme SEP "with" -> VernacScheme l ] ]
;
gallina_ext:
[ [ b = record_token; oc = opt_coercion; name = identref;
ps = LIST0 binder_let; ":";
s = lconstr; ":="; cstr = OPT identref; "{";
fs = LIST0 record_field SEP ";"; "}" ->
VernacRecord (b,(oc,name),ps,s,cstr,fs)
(* Non porté ?
| f = finite_token; s = csort; id = identref;
indpar = LIST0 simple_binder; ":="; lc = constructor_list ->
VernacInductive (f,[id,None,indpar,s,lc])
*)
] ]
;
thm_token:
[ [ "Theorem" -> Theorem
| IDENT "Lemma" -> Lemma
| IDENT "Fact" -> Fact
| IDENT "Remark" -> Remark
| IDENT "Corollary" -> Corollary
| IDENT "Proposition" -> Proposition
| IDENT "Property" -> Property ] ]
;
def_token:
[ [ "Definition" ->
no_hook, (Global, Options.boxed_definitions(), Definition)
| IDENT "Let" ->
no_hook, (Local, Options.boxed_definitions(), Definition)
| IDENT "Example" ->
no_hook, (Global, Options.boxed_definitions(), Example)
| IDENT "SubClass" -> Class.add_subclass_hook, (Global, false, SubClass)
| IDENT "Local"; IDENT "SubClass" ->
Class.add_subclass_hook, (Local, false, SubClass) ] ]
;
assumption_token:
[ [ "Hypothesis" -> (Local, Logical)
| "Variable" -> (Local, Definitional)
| "Axiom" -> (Global, Logical)
| "Parameter" -> (Global, Definitional)
| IDENT "Conjecture" -> (Global, Conjectural) ] ]
;
assumptions_token:
[ [ IDENT "Hypotheses" -> (Local, Logical)
| IDENT "Variables" -> (Local, Definitional)
| IDENT "Axioms" -> (Global, Logical)
| IDENT "Parameters" -> (Global, Definitional) ] ]
;
finite_token:
[ [ "Inductive" -> true
| "CoInductive" -> false ] ]
;
record_token:
[ [ IDENT "Record" -> true | IDENT "Structure" -> false ] ]
;
(* Simple definitions *)
def_body:
[ [ bl = LIST0 binder_let; ":="; red = reduce; c = lconstr ->
(match c with
CCast(_,c, Rawterm.CastConv (k,t)) -> DefineBody (bl, red, c, Some t)
| _ -> DefineBody (bl, red, c, None))
| bl = LIST0 binder_let; ":"; t = lconstr; ":="; red = reduce; c = lconstr ->
DefineBody (bl, red, c, Some t)
| bl = LIST0 binder_let; ":"; t = lconstr ->
ProveBody (bl, t) ] ]
;
reduce:
[ [ IDENT "Eval"; r = Tactic.red_expr; "in" -> Some r
| -> None ] ]
;
decl_notation:
[ [ OPT [ "where"; ntn = ne_string; ":="; c = constr;
scopt = OPT [ ":"; sc = IDENT -> sc] -> (ntn,c,scopt) ] ] ]
;
(* Inductives and records *)
inductive_definition:
[ [ id = identref; indpar = LIST0 binder_let; ":"; c = lconstr;
":="; lc = constructor_list; ntn = decl_notation ->
((id,indpar,c,lc),ntn) ] ]
;
constructor_list:
[ [ "|"; l = LIST1 constructor SEP "|" -> l
| l = LIST1 constructor SEP "|" -> l
| -> [] ] ]
;
(*
csort:
[ [ s = sort -> CSort (loc,s) ] ]
;
*)
opt_coercion:
[ [ ">" -> true
| -> false ] ]
;
(* (co)-fixpoints *)
rec_definition:
[ [ id = ident; bl = LIST1 binder_let;
annot = rec_annotation; ty = type_cstr;
":="; def = lconstr; ntn = decl_notation ->
let names = List.map snd (names_of_local_assums bl) in
let ni =
match fst annot with
Some id ->
(try Some (list_index (Name id) names - 1)
with Not_found -> Util.user_err_loc
(loc,"Fixpoint",
Pp.str "No argument named " ++ Nameops.pr_id id))
| None ->
(* If there is only one argument, it is the recursive one,
otherwise, we search the recursive index later *)
if List.length names = 1 then Some 0 else None
in
((id,(ni,snd annot),bl,ty,def),ntn) ] ]
;
corec_definition:
[ [ id = ident; bl = LIST0 binder_let; ty = type_cstr; ":=";
def = lconstr; ntn = decl_notation ->
((id,bl,ty,def),ntn) ] ]
;
rec_annotation:
[ [ "{"; IDENT "struct"; id=IDENT; "}" -> (Some (id_of_string id), CStructRec)
| "{"; IDENT "wf"; rel=constr; id=OPT IDENT; "}" -> (option_map id_of_string id, CWfRec rel)
| "{"; IDENT "measure"; rel=constr; id=OPT IDENT; "}" -> (option_map id_of_string id, CMeasureRec rel)
| -> (None, CStructRec)
] ]
;
type_cstr:
[ [ ":"; c=lconstr -> c
| -> CHole loc ] ]
;
(* Inductive schemes *)
scheme:
[ [ id = identref; ":="; dep = dep_scheme; "for"; ind = global;
IDENT "Sort"; s = sort ->
(id,dep,ind,s) ] ]
;
dep_scheme:
[ [ IDENT "Induction" -> true
| IDENT "Minimality" -> false ] ]
;
(* Various Binders *)
(*
(* ... without coercions *)
binder_nodef:
[ [ b = binder_let ->
(match b with
LocalRawAssum(l,ty) -> (l,ty)
| LocalRawDef _ ->
Util.user_err_loc
(loc,"fix_param",Pp.str"defined binder not allowed here")) ] ]
;
*)
(* ... with coercions *)
record_field:
[ [ id = name -> (false,AssumExpr(id,CHole loc))
| id = name; oc = of_type_with_opt_coercion; t = lconstr ->
(oc,AssumExpr (id,t))
| id = name; oc = of_type_with_opt_coercion;
t = lconstr; ":="; b = lconstr -> (oc,DefExpr (id,b,Some t))
| id = name; ":="; b = lconstr ->
match b with
CCast(_,b, Rawterm.CastConv (_, t)) -> (false,DefExpr(id,b,Some t))
| _ -> (false,DefExpr(id,b,None)) ] ]
;
assum_list:
[ [ bl = LIST1 assum_coe -> bl | b = simple_assum_coe -> [b] ] ]
;
assum_coe:
[ [ "("; a = simple_assum_coe; ")" -> a ] ]
;
simple_assum_coe:
[ [ idl = LIST1 identref; oc = of_type_with_opt_coercion; c = lconstr ->
(oc,(idl,c)) ] ]
;
constructor:
[ [ id = identref; l = LIST0 binder_let;
coe = of_type_with_opt_coercion; c = lconstr ->
(coe,(id,G_constr.mkCProdN loc l c))
| id = identref; l = LIST0 binder_let ->
(false,(id,G_constr.mkCProdN loc l (CHole loc))) ] ]
;
of_type_with_opt_coercion:
[ [ ":>" -> true
| ":"; ">" -> true
| ":" -> false ] ]
;
END
(* Modules and Sections *)
GEXTEND Gram
GLOBAL: gallina_ext module_expr module_type;
gallina_ext:
[ [ (* Interactive module declaration *)
IDENT "Module"; export = export_token; id = identref;
bl = LIST0 module_binder; mty_o = OPT of_module_type;
mexpr_o = OPT is_module_expr ->
VernacDefineModule (export, id, bl, mty_o, mexpr_o)
| IDENT "Module"; "Type"; id = identref;
bl = LIST0 module_binder; mty_o = OPT is_module_type ->
VernacDeclareModuleType (id, bl, mty_o)
| IDENT "Declare"; IDENT "Module"; export = export_token; id = identref;
bl = LIST0 module_binder; ":"; mty = module_type ->
VernacDeclareModule (export, id, bl, (mty,true))
(* Section beginning *)
| IDENT "Section"; id = identref -> VernacBeginSection id
| IDENT "Chapter"; id = identref -> VernacBeginSection id
(* This end a Section a Module or a Module Type *)
| IDENT "End"; id = identref -> VernacEndSegment id
(* Requiring an already compiled module *)
| IDENT "Require"; export = export_token; specif = specif_token;
qidl = LIST1 global ->
VernacRequire (export, specif, qidl)
| IDENT "Require"; export = export_token; specif = specif_token;
filename = ne_string ->
VernacRequireFrom (export, specif, filename)
| IDENT "Import"; qidl = LIST1 global -> VernacImport (false,qidl)
| IDENT "Export"; qidl = LIST1 global -> VernacImport (true,qidl) ] ]
;
export_token:
[ [ IDENT "Import" -> Some false
| IDENT "Export" -> Some true
| -> None ] ]
;
specif_token:
[ [ IDENT "Implementation" -> Some false
| IDENT "Specification" -> Some true
| -> None ] ]
;
of_module_type:
[ [ ":"; mty = module_type -> (mty, true)
| "<:"; mty = module_type -> (mty, false) ] ]
;
is_module_type:
[ [ ":="; mty = module_type -> mty ] ]
;
is_module_expr:
[ [ ":="; mexpr = module_expr -> mexpr ] ]
;
(* Module binder *)
module_binder:
[ [ "("; export = export_token; idl = LIST1 identref; ":";
mty = module_type; ")" -> (export,idl,mty) ] ]
;
(* Module expressions *)
module_expr:
[ [ qid = qualid -> CMEident qid
| me1 = module_expr; me2 = module_expr -> CMEapply (me1,me2)
| "("; me = module_expr; ")" -> me
(* ... *)
] ]
;
with_declaration:
[ [ "Definition"; fqid = fullyqualid; ":="; c = Constr.lconstr ->
CWith_Definition (fqid,c)
| IDENT "Module"; fqid = fullyqualid; ":="; qid = qualid ->
CWith_Module (fqid,qid)
] ]
;
module_type:
[ [ qid = qualid -> CMTEident qid
(* ... *)
| mty = module_type; "with"; decl = with_declaration ->
CMTEwith (mty,decl) ] ]
;
END
(* Extensions: implicits, coercions, etc. *)
GEXTEND Gram
GLOBAL: gallina_ext;
gallina_ext:
[ [ (* Transparent and Opaque *)
IDENT "Transparent"; l = LIST1 global -> VernacSetOpacity (false, l)
| IDENT "Opaque"; l = LIST1 global -> VernacSetOpacity (true, l)
(* Canonical structure *)
| IDENT "Canonical"; IDENT "Structure"; qid = global ->
VernacCanonical qid
| IDENT "Canonical"; IDENT "Structure"; qid = global; d = def_body ->
let s = coerce_global_to_id qid in
VernacDefinition
((Global,false,CanonicalStructure),(dummy_loc,s),d,
(fun _ -> Recordops.declare_canonical_structure))
(* Coercions *)
| IDENT "Coercion"; qid = global; d = def_body ->
let s = coerce_global_to_id qid in
VernacDefinition ((Global,false,Coercion),(dummy_loc,s),d,Class.add_coercion_hook)
| IDENT "Coercion"; IDENT "Local"; qid = global; d = def_body ->
let s = coerce_global_to_id qid in
VernacDefinition ((Local,false,Coercion),(dummy_loc,s),d,Class.add_coercion_hook)
| IDENT "Identity"; IDENT "Coercion"; IDENT "Local"; f = identref;
":"; s = class_rawexpr; ">->"; t = class_rawexpr ->
VernacIdentityCoercion (Local, f, s, t)
| IDENT "Identity"; IDENT "Coercion"; f = identref; ":";
s = class_rawexpr; ">->"; t = class_rawexpr ->
VernacIdentityCoercion (Global, f, s, t)
| IDENT "Coercion"; IDENT "Local"; qid = global; ":";
s = class_rawexpr; ">->"; t = class_rawexpr ->
VernacCoercion (Local, qid, s, t)
| IDENT "Coercion"; qid = global; ":"; s = class_rawexpr; ">->";
t = class_rawexpr ->
VernacCoercion (Global, qid, s, t)
(* Implicit *)
| IDENT "Implicit"; IDENT "Arguments"; qid = global;
pos = OPT [ "["; l = LIST0 ident; "]" -> l ] ->
let pos = option_map (List.map (fun id -> ExplByName id)) pos in
VernacDeclareImplicits (true,qid,pos)
| IDENT "Implicit"; ["Type" | IDENT "Types"];
idl = LIST1 identref; ":"; c = lconstr -> VernacReserve (idl,c) ] ]
;
END
GEXTEND Gram
GLOBAL: command check_command class_rawexpr;
command:
[ [ IDENT "Comments"; l = LIST0 comment -> VernacComments l
(* System directory *)
| IDENT "Pwd" -> VernacChdir None
| IDENT "Cd" -> VernacChdir None
| IDENT "Cd"; dir = ne_string -> VernacChdir (Some dir)
(* Toplevel control *)
| IDENT "Drop" -> VernacToplevelControl Drop
| IDENT "ProtectedLoop" -> VernacToplevelControl ProtectedLoop
| IDENT "Quit" -> VernacToplevelControl Quit
| IDENT "Load"; verbosely = [ IDENT "Verbose" -> true | -> false ];
s = [ s = ne_string -> s | s = IDENT -> s ] ->
VernacLoad (verbosely, s)
| IDENT "Declare"; IDENT "ML"; IDENT "Module"; l = LIST1 ne_string ->
VernacDeclareMLModule l
| IDENT "Dump"; IDENT "Universes"; fopt = OPT ne_string ->
error "This command is deprecated, use Print Universes"
| IDENT "Locate"; l = locatable -> VernacLocate l
(* Managing load paths *)
| IDENT "Add"; IDENT "LoadPath"; dir = ne_string; alias = as_dirpath ->
VernacAddLoadPath (false, dir, alias)
| IDENT "Add"; IDENT "Rec"; IDENT "LoadPath"; dir = ne_string;
alias = as_dirpath -> VernacAddLoadPath (true, dir, alias)
| IDENT "Remove"; IDENT "LoadPath"; dir = ne_string ->
VernacRemoveLoadPath dir
(* For compatibility *)
| IDENT "AddPath"; dir = ne_string; "as"; alias = as_dirpath ->
VernacAddLoadPath (false, dir, alias)
| IDENT "AddRecPath"; dir = ne_string; "as"; alias = as_dirpath ->
VernacAddLoadPath (true, dir, alias)
| IDENT "DelPath"; dir = ne_string ->
VernacRemoveLoadPath dir
(* Type-Checking (pas dans le refman) *)
| "Type"; c = lconstr -> VernacGlobalCheck c
(* Printing (careful factorization of entries) *)
| IDENT "Print"; p = printable -> VernacPrint p
| IDENT "Print"; qid = global -> VernacPrint (PrintName qid)
| IDENT "Print"; IDENT "Module"; "Type"; qid = global ->
VernacPrint (PrintModuleType qid)
| IDENT "Print"; IDENT "Module"; qid = global ->
VernacPrint (PrintModule qid)
| IDENT "Inspect"; n = natural -> VernacPrint (PrintInspect n)
| IDENT "About"; qid = global -> VernacPrint (PrintAbout qid)
(* Searching the environment *)
| IDENT "Search"; qid = global; l = in_or_out_modules ->
VernacSearch (SearchHead qid, l)
| IDENT "SearchPattern"; c = constr_pattern; l = in_or_out_modules ->
VernacSearch (SearchPattern c, l)
| IDENT "SearchRewrite"; c = constr_pattern; l = in_or_out_modules ->
VernacSearch (SearchRewrite c, l)
| IDENT "SearchAbout";
sl = [ "["; l = LIST1 [ r = global -> SearchRef r
| s = ne_string -> SearchString s ]; "]" -> l
| qid = global -> [SearchRef qid] ];
l = in_or_out_modules ->
VernacSearch (SearchAbout sl, l)
| IDENT "Add"; IDENT "ML"; IDENT "Path"; dir = ne_string ->
VernacAddMLPath (false, dir)
| IDENT "Add"; IDENT "Rec"; IDENT "ML"; IDENT "Path"; dir = ne_string ->
VernacAddMLPath (true, dir)
(* Pour intervenir sur les tables de paramètres *)
| "Set"; table = IDENT; field = IDENT; v = option_value ->
VernacSetOption (SecondaryTable (table,field),v)
| "Set"; table = IDENT; field = IDENT; lv = LIST1 option_ref_value ->
VernacAddOption (SecondaryTable (table,field),lv)
| "Set"; table = IDENT; field = IDENT ->
VernacSetOption (SecondaryTable (table,field),BoolValue true)
| IDENT "Unset"; table = IDENT; field = IDENT ->
VernacUnsetOption (SecondaryTable (table,field))
| IDENT "Unset"; table = IDENT; field = IDENT; lv = LIST1 option_ref_value ->
VernacRemoveOption (SecondaryTable (table,field),lv)
| "Set"; table = IDENT; value = option_value ->
VernacSetOption (PrimaryTable table, value)
| "Set"; table = IDENT ->
VernacSetOption (PrimaryTable table, BoolValue true)
| IDENT "Unset"; table = IDENT ->
VernacUnsetOption (PrimaryTable table)
| IDENT "Print"; IDENT "Table"; table = IDENT; field = IDENT ->
VernacPrintOption (SecondaryTable (table,field))
| IDENT "Print"; IDENT "Table"; table = IDENT ->
VernacPrintOption (PrimaryTable table)
| IDENT "Add"; table = IDENT; field = IDENT; v = LIST1 option_ref_value
-> VernacAddOption (SecondaryTable (table,field), v)
(* Un value global ci-dessous va être caché par un field au dessus! *)
| IDENT "Add"; table = IDENT; v = LIST1 option_ref_value ->
VernacAddOption (PrimaryTable table, v)
| IDENT "Test"; table = IDENT; field = IDENT; v = LIST1 option_ref_value
-> VernacMemOption (SecondaryTable (table,field), v)
| IDENT "Test"; table = IDENT; field = IDENT ->
VernacPrintOption (SecondaryTable (table,field))
| IDENT "Test"; table = IDENT; v = LIST1 option_ref_value ->
VernacMemOption (PrimaryTable table, v)
| IDENT "Test"; table = IDENT ->
VernacPrintOption (PrimaryTable table)
| IDENT "Remove"; table = IDENT; field = IDENT; v= LIST1 option_ref_value
-> VernacRemoveOption (SecondaryTable (table,field), v)
| IDENT "Remove"; table = IDENT; v = LIST1 option_ref_value ->
VernacRemoveOption (PrimaryTable table, v)
| IDENT "proof" -> VernacDeclProof
| "return" -> VernacReturn ]]
;
check_command: (* TODO: rapprocher Eval et Check *)
[ [ IDENT "Eval"; r = Tactic.red_expr; "in"; c = lconstr ->
fun g -> VernacCheckMayEval (Some r, g, c)
| IDENT "Check"; c = lconstr ->
fun g -> VernacCheckMayEval (None, g, c) ] ]
;
printable:
[ [ IDENT "Term"; qid = global -> PrintName qid
| IDENT "All" -> PrintFullContext
| IDENT "Section"; s = global -> PrintSectionContext s
| IDENT "Grammar"; ent = IDENT ->
(* This should be in "syntax" section but is here for factorization*)
PrintGrammar ("", ent)
| IDENT "LoadPath" -> PrintLoadPath
| IDENT "Modules" -> PrintModules
| IDENT "ML"; IDENT "Path" -> PrintMLLoadPath
| IDENT "ML"; IDENT "Modules" -> PrintMLModules
| IDENT "Graph" -> PrintGraph
| IDENT "Classes" -> PrintClasses
| IDENT "Ltac"; qid = global -> PrintLtac qid
| IDENT "Coercions" -> PrintCoercions
| IDENT "Coercion"; IDENT "Paths"; s = class_rawexpr; t = class_rawexpr
-> PrintCoercionPaths (s,t)
| IDENT "Canonical"; IDENT "Projections" -> PrintCanonicalConversions
| IDENT "Tables" -> PrintTables
(* Obsolete: was used for cooking V6.3 recipes ??
| IDENT "Proof"; qid = global -> PrintOpaqueName qid
*)
| IDENT "Hint" -> PrintHintGoal
| IDENT "Hint"; qid = global -> PrintHint qid
| IDENT "Hint"; "*" -> PrintHintDb
| IDENT "HintDb"; s = IDENT -> PrintHintDbName s
| "Rewrite"; IDENT "HintDb"; s = IDENT -> PrintRewriteHintDbName s
| IDENT "Setoids" -> PrintSetoids
| IDENT "Scopes" -> PrintScopes
| IDENT "Scope"; s = IDENT -> PrintScope s
| IDENT "Visibility"; s = OPT IDENT -> PrintVisibility s
| IDENT "Implicit"; qid = global -> PrintImplicit qid
| IDENT "Universes"; fopt = OPT ne_string -> PrintUniverses fopt ] ]
;
class_rawexpr:
[ [ IDENT "Funclass" -> FunClass
| IDENT "Sortclass" -> SortClass
| qid = global -> RefClass qid ] ]
;
locatable:
[ [ qid = global -> LocateTerm qid
| IDENT "File"; f = ne_string -> LocateFile f
| IDENT "Library"; qid = global -> LocateLibrary qid
| IDENT "Module"; qid = global -> LocateModule qid
| s = ne_string -> LocateNotation s ] ]
;
option_value:
[ [ n = integer -> IntValue n
| s = STRING -> StringValue s ] ]
;
option_ref_value:
[ [ id = global -> QualidRefValue id
| s = STRING -> StringRefValue s ] ]
;
as_dirpath:
[ [ d = OPT [ "as"; d = dirpath -> d ] -> d ] ]
;
in_or_out_modules:
[ [ IDENT "inside"; l = LIST1 global -> SearchInside l
| IDENT "outside"; l = LIST1 global -> SearchOutside l
| -> SearchOutside [] ] ]
;
comment:
[ [ c = constr -> CommentConstr c
| s = STRING -> CommentString s
| n = natural -> CommentInt n ] ]
;
END;
GEXTEND Gram
command:
[ [
(* State management *)
IDENT "Write"; IDENT "State"; s = IDENT -> VernacWriteState s
| IDENT "Write"; IDENT "State"; s = ne_string -> VernacWriteState s
| IDENT "Restore"; IDENT "State"; s = IDENT -> VernacRestoreState s
| IDENT "Restore"; IDENT "State"; s = ne_string -> VernacRestoreState s
(* Resetting *)
| IDENT "Reset"; id = identref -> VernacResetName id
| IDENT "Reset"; IDENT "Initial" -> VernacResetInitial
| IDENT "Back" -> VernacBack 1
| IDENT "Back"; n = natural -> VernacBack n
| IDENT "BackTo"; n = natural -> VernacBackTo n
| IDENT "Backtrack"; n = natural ; m = natural ; p = natural ->
VernacBacktrack (n,m,p)
(* Tactic Debugger *)
| IDENT "Debug"; IDENT "On" ->
VernacSetOption (SecondaryTable ("Ltac","Debug"), BoolValue true)
| IDENT "Debug"; IDENT "Off" ->
VernacSetOption (SecondaryTable ("Ltac","Debug"), BoolValue false)
] ];
END
;;
(* Grammar extensions *)
GEXTEND Gram
GLOBAL: syntax;
syntax:
[ [ IDENT "Open"; local = locality; IDENT "Scope"; sc = IDENT ->
VernacOpenCloseScope (local,true,sc)
| IDENT "Close"; local = locality; IDENT "Scope"; sc = IDENT ->
VernacOpenCloseScope (local,false,sc)
| IDENT "Delimit"; IDENT "Scope"; sc = IDENT; "with"; key = IDENT ->
VernacDelimiters (sc,key)
| IDENT "Bind"; IDENT "Scope"; sc = IDENT; "with";
refl = LIST1 class_rawexpr -> VernacBindScope (sc,refl)
| IDENT "Arguments"; IDENT "Scope"; qid = global;
"["; scl = LIST0 opt_scope; "]" -> VernacArgumentsScope (true,qid,scl)
| IDENT "Infix"; local = locality;
op = ne_string; ":="; p = global;
modl = [ "("; l = LIST1 syntax_modifier SEP ","; ")" -> l | -> [] ];
sc = OPT [ ":"; sc = IDENT -> sc ] ->
VernacInfix (local,(op,modl),p,sc)
| IDENT "Notation"; local = locality; id = ident; ":="; c = constr;
b = [ "("; IDENT "only"; IDENT "parsing"; ")" -> true | -> false ] ->
VernacSyntacticDefinition (id,c,local,b)
| IDENT "Notation"; local = locality; s = ne_string; ":="; c = constr;
modl = [ "("; l = LIST1 syntax_modifier SEP ","; ")" -> l | -> [] ];
sc = OPT [ ":"; sc = IDENT -> sc ] ->
VernacNotation (local,c,(s,modl),sc)
| IDENT "Tactic"; IDENT "Notation"; n = tactic_level;
pil = LIST1 production_item; ":="; t = Tactic.tactic
-> VernacTacticNotation (n,pil,t)
| IDENT "Reserved"; IDENT "Notation"; local = locality; s = ne_string;
l = [ "("; l = LIST1 syntax_modifier SEP ","; ")" -> l | -> [] ]
-> VernacSyntaxExtension (local,(s,l))
(* "Print" "Grammar" should be here but is in "command" entry in order
to factorize with other "Print"-based vernac entries *)
] ]
;
tactic_level:
[ [ "("; "at"; IDENT "level"; n = natural; ")" -> n | -> 0 ] ]
;
locality:
[ [ IDENT "Local" -> true | -> false ] ]
;
level:
[ [ IDENT "level"; n = natural -> NumLevel n
| IDENT "next"; IDENT "level" -> NextLevel ] ]
;
syntax_modifier:
[ [ x = IDENT; "at"; lev = level -> SetItemLevel ([x],lev)
| x = IDENT; ","; l = LIST1 IDENT SEP ","; "at";
lev = level -> SetItemLevel (x::l,lev)
| "at"; IDENT "level"; n = natural -> SetLevel n
| IDENT "left"; IDENT "associativity" -> SetAssoc Gramext.LeftA
| IDENT "right"; IDENT "associativity" -> SetAssoc Gramext.RightA
| IDENT "no"; IDENT "associativity" -> SetAssoc Gramext.NonA
| x = IDENT; typ = syntax_extension_type -> SetEntryType (x,typ)
| IDENT "only"; IDENT "parsing" -> SetOnlyParsing
| IDENT "format"; s = [s = STRING -> (loc,s)] -> SetFormat s ] ]
;
syntax_extension_type:
[ [ IDENT "ident" -> ETIdent | IDENT "global" -> ETReference
| IDENT "bigint" -> ETBigint
] ]
;
opt_scope:
[ [ "_" -> None | sc = IDENT -> Some sc ] ]
;
production_item:
[ [ s = ne_string -> VTerm s
| nt = IDENT; po = OPT [ "("; p = ident; ")" -> p ] ->
VNonTerm (loc,nt,po) ] ]
;
END
|