-
Notifications
You must be signed in to change notification settings - Fork 632
/
ppvernac.ml
1423 lines (1294 loc) · 50 KB
/
ppvernac.ml
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
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
(************************************************************************)
(* * The Coq Proof Assistant / The Coq Development Team *)
(* v * Copyright INRIA, CNRS and contributors *)
(* <O___,, * (see version control and CREDITS file for authors & dates) *)
(* \VV/ **************************************************************)
(* // * This file is distributed under the terms of the *)
(* * GNU Lesser General Public License Version 2.1 *)
(* * (see LICENSE file for the text of the license) *)
(************************************************************************)
open Pp
open Names
open CErrors
open Util
open CAst
open Extend
open Constrexpr
open Vernacexpr
open Declaremods
open Pputils
open Ppconstr
let do_not_tag _ x = x
let tag_keyword = do_not_tag ()
let tag_vernac = do_not_tag
let keyword s = tag_keyword (str s)
let pr_smart_global = Pputils.pr_or_by_notation pr_qualid
let pr_in_global_env f c : Pp.t =
let env = Global.env () in
let sigma = Evd.from_env env in
f env sigma c
(* when not !Flags.beautify_file these just ignore the env/sigma *)
let pr_constr_expr = pr_in_global_env pr_constr_expr
let pr_lconstr_expr = pr_in_global_env pr_lconstr_expr
let pr_binders = pr_in_global_env pr_binders
let pr_constr_pattern_expr = pr_in_global_env pr_constr_pattern_expr
(* In principle this may use the env/sigma, in practice not sure if it
does except through pr_constr_expr in beautify mode. *)
let pr_gen = pr_in_global_env Pputils.pr_raw_generic
(* No direct Global.env or pr_in_global_env use after this *)
let pr_constr = pr_constr_expr
let pr_lconstr = pr_lconstr_expr
let pr_spc_lconstr =
pr_sep_com spc @@ pr_lconstr_expr
let pr_red_expr =
Ppred.pr_red_expr
(pr_constr_expr, pr_lconstr_expr, pr_smart_global, pr_constr_expr, pr_or_var int)
keyword
let pr_uconstraint (l, d, r) =
pr_sort_name_expr l ++ spc () ++ Univ.pr_constraint_type d ++ spc () ++
pr_sort_name_expr r
let pr_full_univ_name_list = function
| None -> mt()
| Some (ql, ul) ->
str "@{" ++ prlist_with_sep spc pr_lname ql ++
(if List.is_empty ql then mt() else strbrk " | ") ++
prlist_with_sep spc pr_lname ul ++ str "}"
let pr_variance_lident (lid,v) =
let v = Option.cata UVars.Variance.pr (mt()) v in
v ++ pr_lident lid
let pr_univdecl_instance l extensible =
prlist_with_sep spc pr_lident l ++
(if extensible then str"+" else mt ())
let pr_cumul_univdecl_instance l extensible =
prlist_with_sep spc pr_variance_lident l ++
(if extensible then str"+" else mt ())
let pr_univdecl_constraints l extensible =
if List.is_empty l && extensible then mt ()
else str"|" ++ spc () ++ prlist_with_sep (fun () -> strbrk" | ") pr_uconstraint l ++
(if extensible then str"+" else mt())
let pr_universe_decl l =
let open UState in
match l with
| None -> mt ()
| Some l ->
str"@{" ++ pr_univdecl_instance l.univdecl_instance l.univdecl_extensible_instance ++
pr_univdecl_constraints l.univdecl_constraints l.univdecl_extensible_constraints ++ str "}"
let pr_cumul_univ_decl l =
let open UState in
match l with
| None -> mt ()
| Some l ->
str"@{" ++ pr_cumul_univdecl_instance l.univdecl_instance l.univdecl_extensible_instance ++
pr_univdecl_constraints l.univdecl_constraints l.univdecl_extensible_constraints ++ str "}"
let pr_ident_decl (lid, l) =
pr_lident lid ++ pr_universe_decl l
let pr_cumul_ident_decl (lid, l) =
pr_lident lid ++ pr_cumul_univ_decl l
let string_of_fqid fqid =
String.concat "." (List.map Id.to_string fqid)
let pr_fqid fqid = str (string_of_fqid fqid)
let pr_lfqid {CAst.loc;v=fqid} =
match loc with
| None -> pr_fqid fqid
| Some loc -> let (b,_) = Loc.unloc loc in
pr_located pr_fqid @@ Loc.tag ~loc:(Loc.make_loc (b,b + String.length (string_of_fqid fqid))) fqid
let pr_lname_decl (n, u) =
pr_lname n ++ pr_universe_decl u
let pr_ltac_ref = Libnames.pr_qualid
let pr_module = Libnames.pr_qualid
let pr_import_cats = function
| None -> mt()
| Some {negative;import_cats=cats} ->
(if negative then str "-" else mt()) ++
str "(" ++
prlist_with_sep (fun () -> str ",") (fun x -> str x.v) cats ++
str ")"
let pr_one_import_filter_name (q,etc) =
Libnames.pr_qualid q ++ if etc then str "(..)" else mt()
let pr_import_module (m,f) =
Libnames.pr_qualid m ++ match f with
| ImportAll -> mt()
| ImportNames ns -> surround (prlist_with_sep pr_comma pr_one_import_filter_name ns)
let sep_end = function
| VernacSynPure (VernacBullet _ | VernacSubproof _ | VernacEndSubproof) -> mt()
| _ -> str"."
let sep = fun _ -> spc()
let sep_v2 = fun _ -> str"," ++ spc()
let string_of_theorem_kind = let open Decls in function
| Theorem -> "Theorem"
| Lemma -> "Lemma"
| Fact -> "Fact"
| Remark -> "Remark"
| Property -> "Property"
| Proposition -> "Proposition"
| Corollary -> "Corollary"
let string_of_definition_object_kind = let open Decls in function
| Definition -> "Definition"
| Example -> "Example"
| Coercion -> "Coercion"
| SubClass -> "SubClass"
| CanonicalStructure -> "Canonical Structure"
| Instance -> "Instance"
| Let -> "Let"
| LetContext -> CErrors.anomaly (Pp.str "Bound to Context.")
| (StructureComponent|Scheme|CoFixpoint|Fixpoint|IdentityCoercion|Method) ->
CErrors.anomaly (Pp.str "Internal definition kind.")
let string_of_assumption_kind = let open Decls in function
| Definitional -> "Parameter"
| Logical -> "Axiom"
| Conjectural -> "Conjecture"
| Context -> "Context"
let string_of_logical_kind = let open Decls in function
| IsAssumption k -> string_of_assumption_kind k
| IsDefinition k -> string_of_definition_object_kind k
| IsProof k -> string_of_theorem_kind k
| IsPrimitive -> "Primitive"
| IsSymbol -> "Symbol"
let pr_notation_entry = function
| InConstrEntry -> keyword "constr"
| InCustomEntry s -> keyword "custom" ++ spc () ++ str s
let pr_abbreviation pr (ids, c) =
pr c ++ spc () ++ prlist_with_sep spc pr_id ids
let pr_at_level = function
| NumLevel n -> spc () ++ keyword "at" ++ spc () ++ keyword "level" ++ spc () ++ int n
| NextLevel -> spc () ++ keyword "at" ++ spc () ++ keyword "next" ++ spc () ++ keyword "level"
| DefaultLevel -> mt ()
let level_of_pattern_level = function None -> DefaultLevel | Some n -> NumLevel n
let pr_constr_as_binder_kind = let open Notation_term in function
| AsIdent -> spc () ++ keyword "as ident"
| AsName -> spc () ++ keyword "as name"
| AsAnyPattern -> spc () ++ keyword "as pattern"
| AsStrictPattern -> spc () ++ keyword "as strict pattern"
let pr_strict b = if b then str "strict " else mt ()
let pr_set_entry_type pr = function
| ETIdent -> str"ident"
| ETName -> str"name"
| ETGlobal -> str"global"
| ETPattern (b,n) -> pr_strict b ++ str"pattern" ++ pr_at_level (level_of_pattern_level n)
| ETConstr (s,bko,lev) -> pr_notation_entry s ++ pr lev ++ pr_opt pr_constr_as_binder_kind bko
| ETBigint -> str "bigint"
| ETBinder true -> str "binder"
| ETBinder false -> str "closed binder"
let pr_set_simple_entry_type =
pr_set_entry_type pr_at_level
let pr_comment pr_c = function
| CommentConstr c -> pr_c c
| CommentString s -> qs s
| CommentInt n -> int n
let pr_in_out_modules = function
| SearchInside l -> spc() ++ keyword "inside" ++ spc() ++ prlist_with_sep sep pr_module l
| SearchOutside [] -> mt()
| SearchOutside l -> spc() ++ keyword "outside" ++ spc() ++ prlist_with_sep sep pr_module l
let pr_search_where = function
| Anywhere, false -> mt ()
| Anywhere, true -> str "head:"
| InHyp, true -> str "headhyp:"
| InHyp, false -> str "hyp:"
| InConcl, true -> str "headconcl:"
| InConcl, false -> str "concl:"
let pr_delimiter_depth = function
| DelimOnlyTmpScope -> str "%_"
| DelimUnboundedScope -> str "%"
let pr_scope_delimiter (d, sc) = pr_delimiter_depth d ++ str sc
let pr_search_item = function
| SearchSubPattern (where,p) ->
pr_search_where where ++ pr_constr_pattern_expr p
| SearchString (where,s,sc) -> pr_search_where where ++ qs s ++ pr_opt pr_scope_delimiter sc
| SearchKind kind -> str "is:" ++ str (string_of_logical_kind kind)
let rec pr_search_request = function
| SearchLiteral a -> pr_search_item a
| SearchDisjConj l -> str "[" ++ prlist_with_sep spc (prlist_with_sep pr_bar pr_search_default) l ++ str "]"
and pr_search_default (b, s) =
(if b then mt() else str "-") ++ pr_search_request s
let pr_search a gopt b pr_p =
pr_opt (fun g -> Goal_select.pr_goal_selector g ++ str ":"++ spc()) gopt
++
match a with
| SearchPattern c -> keyword "SearchPattern" ++ spc() ++ pr_p c ++ pr_in_out_modules b
| SearchRewrite c -> keyword "SearchRewrite" ++ spc() ++ pr_p c ++ pr_in_out_modules b
| Search sl ->
keyword "Search" ++ spc() ++ prlist_with_sep spc pr_search_default sl ++ pr_in_out_modules b
let pr_option_ref_value = function
| Goptions.QualidRefValue id -> pr_qualid id
| Goptions.StringRefValue s -> qs s
let pr_printoption table b =
prlist_with_sep spc str table ++
pr_opt (prlist_with_sep sep pr_option_ref_value) b
let pr_set_option a b =
pr_printoption a None ++ (match b with
| OptionUnset | OptionSetTrue -> mt()
| OptionSetInt n -> spc() ++ int n
| OptionSetString s -> spc() ++ quote (str s))
let pr_opt_hintbases l = match l with
| [] -> mt()
| _ as z -> str":" ++ spc() ++ prlist_with_sep sep str z
let pr_reference_or_constr pr_c = function
| HintsReference r -> pr_qualid r
| HintsConstr c -> pr_c c
let pr_hint_mode = let open Hints in function
| ModeInput -> str"+"
| ModeNoHeadEvar -> str"!"
| ModeOutput -> str"-"
let pr_hint_info pr_pat { Typeclasses.hint_priority = pri; hint_pattern = pat } =
pr_opt (fun x -> str"|" ++ int x) pri ++
pr_opt (fun y -> (if Option.is_empty pri then str"| " else mt()) ++ pr_pat y) pat
let pr_hints db h pr_c pr_pat =
let opth = pr_opt_hintbases db in
let pph =
let open Hints in
match h with
| HintsResolve l ->
keyword "Resolve " ++ prlist_with_sep sep
(fun (info, _, c) -> pr_reference_or_constr pr_c c ++ pr_hint_info pr_pat info)
l
| HintsResolveIFF (l2r, l, n) ->
keyword "Resolve " ++ str (if l2r then "->" else "<-")
++ prlist_with_sep sep pr_qualid l
| HintsImmediate l ->
keyword "Immediate" ++ spc() ++
prlist_with_sep sep (fun c -> pr_reference_or_constr pr_c c) l
| HintsUnfold l ->
keyword "Unfold" ++ spc () ++ prlist_with_sep sep pr_qualid l
| HintsTransparency (l, b) ->
keyword (if b then "Transparent" else "Opaque")
++ spc ()
++ (match l with
| HintsVariables -> keyword "Variables"
| HintsConstants -> keyword "Constants"
| HintsReferences l -> prlist_with_sep sep pr_qualid l)
| HintsMode (m, l) ->
keyword "Mode"
++ spc ()
++ pr_qualid m ++ spc() ++
prlist_with_sep spc pr_hint_mode l
| HintsConstructors c ->
keyword "Constructors"
++ spc() ++ prlist_with_sep spc pr_qualid c
| HintsExtern (n,c,tac) ->
let pat = match c with None -> mt () | Some pat -> pr_pat pat in
keyword "Extern" ++ spc() ++ int n ++ spc() ++ pat ++ str" =>" ++
spc() ++ pr_gen tac
in
hov 2 (keyword "Hint "++ pph ++ opth)
let pr_with_declaration pr_c = function
| CWith_Definition (id,udecl,c) ->
let p = pr_c c in
keyword "Definition" ++ spc() ++ pr_lfqid id ++ pr_universe_decl udecl ++ str" := " ++ p
| CWith_Module (id,qid) ->
keyword "Module" ++ spc() ++ pr_lfqid id ++ str" := " ++
pr_qualid qid
let rec pr_module_ast leading_space pr_c = function
| { loc ; v = CMident qid } ->
if leading_space then
spc () ++ pr_located pr_qualid (loc, qid)
else
pr_located pr_qualid (loc,qid)
| { v = CMwith (mty,decl) } ->
let m = pr_module_ast leading_space pr_c mty in
let p = pr_with_declaration pr_c decl in
m ++ spc() ++ keyword "with" ++ spc() ++ p
| { v = CMapply (me1, me2 ) } ->
pr_module_ast leading_space pr_c me1 ++ spc() ++ pr_located pr_qualid (me2.loc, me2)
let pr_inline = function
| DefaultInline -> mt ()
| NoInline -> str "[no inline]"
| InlineAt i -> str "[inline at level " ++ int i ++ str "]"
let pr_assumption_inline = function
| DefaultInline -> str "Inline"
| NoInline -> mt ()
| InlineAt i -> str "Inline(" ++ int i ++ str ")"
let pr_module_ast_inl leading_space pr_c (mast,inl) =
pr_module_ast leading_space pr_c mast ++ pr_inline inl
let pr_of_module_type prc = function
| Enforce mty -> str ":" ++ pr_module_ast_inl true prc mty
| Check mtys ->
prlist_strict (fun m -> str "<:" ++ pr_module_ast_inl true prc m) mtys
let pr_export_flag = function
| Export -> keyword "Export"
| Import -> keyword "Import"
let pr_export_with_cats (export,cats) =
pr_export_flag export ++ pr_import_cats cats
let pr_require_token = function
| Some export ->
pr_export_with_cats export ++ spc ()
| None -> mt()
let pr_module_vardecls pr_c (export,idl,(mty,inl)) =
let m = pr_module_ast true pr_c mty in
spc() ++
hov 1 (str"(" ++ pr_require_token export ++
prlist_with_sep spc pr_lident idl ++ str":" ++ m ++ str")")
let pr_module_binders l pr_c =
prlist_strict (pr_module_vardecls pr_c) l
let pr_type_option pr_c = function
| { v = CHole (Some GNamedHole _) } as c -> brk(0,2) ++ str" :" ++ pr_c c
| { v = CHole _ } -> mt()
| _ as c -> brk(0,2) ++ str" :" ++ pr_c c
let pr_binders_arg =
pr_non_empty_arg @@ pr_binders
let pr_and_type_binders_arg bl =
pr_binders_arg bl
let pr_onescheme (idop, {sch_type; sch_qualid; sch_sort}) =
let str_identifier = match idop with
| Some id -> pr_lident id ++ str " :="
| None -> str "" in
let str_scheme = match sch_type with
| SchemeInduction -> keyword "Induction for"
| SchemeMinimality -> keyword "Minimality for"
| SchemeElimination -> keyword "Elimination for"
| SchemeCase -> keyword "Case for" in
hov 0 str_identifier ++ spc () ++ hov 0 (str_scheme ++ spc() ++ pr_smart_global sch_qualid)
++ spc () ++ hov 0 (keyword "Sort" ++ spc() ++ Sorts.pr_sort_family sch_sort)
let pr_equality_scheme_type sch id =
let str_scheme = match sch with
| SchemeBooleanEquality -> keyword "Boolean Equality for"
| SchemeEquality -> keyword "Equality for" in
hov 0 (str_scheme ++ spc() ++ pr_smart_global id)
let begin_of_inductive = function
| [] -> 0
| (_,({loc},_))::_ -> Option.cata (fun loc -> fst (Loc.unloc loc)) 0 loc
let pr_class_rawexpr = function
| FunClass -> keyword "Funclass"
| SortClass -> keyword "Sortclass"
| RefClass qid -> pr_smart_global qid
let pr_assumption_token many discharge kind =
match discharge, kind with
| (NoDischarge,Decls.Logical) ->
keyword (if many then "Axioms" else "Axiom")
| (NoDischarge,Decls.Definitional) ->
keyword (if many then "Parameters" else "Parameter")
| (NoDischarge,Decls.Conjectural) -> str"Conjecture"
| (DoDischarge,Decls.Logical) ->
keyword (if many then "Hypotheses" else "Hypothesis")
| (DoDischarge,Decls.Definitional) ->
keyword (if many then "Variables" else "Variable")
| (DoDischarge,Decls.Conjectural) ->
anomaly (Pp.str "Don't know how to beautify a local conjecture.")
| (_,Decls.Context) ->
anomaly (Pp.str "Context is used only internally.")
let pr_params pr_c (xl,(c,t)) =
hov 2 (prlist_with_sep sep pr_lident xl ++ spc() ++
(if c then str":>" else str":" ++
spc() ++ pr_c t))
let rec factorize = function
| [] -> []
| (c,(idl,t))::l ->
match factorize l with
| (xl,((c', t') as r))::l'
when (c : bool) == c' && (=) t t' ->
(* FIXME: we need equality on constr_expr *)
(idl@xl,r)::l'
| l' -> (idl,(c,t))::l'
let pr_ne_params_list pr_c l =
match factorize l with
| [p] -> pr_params pr_c p
| l ->
prlist_with_sep spc
(fun p -> hov 1 (str "(" ++ pr_params pr_c p ++ str ")")) l
(*
prlist_with_sep pr_semicolon (pr_params pr_c)
*)
let pr_thm_token k = keyword (string_of_theorem_kind k)
let pr_syntax_modifier = let open Gramlib.Gramext in CAst.with_val (function
| SetItemLevel (l,bko,n) ->
prlist_with_sep sep_v2 str l ++ spc () ++ pr_at_level n ++
pr_opt pr_constr_as_binder_kind bko
| SetItemScope (l,s) ->
prlist_with_sep sep_v2 str l ++ spc () ++ str"in scope" ++ str s
| SetLevel n -> pr_at_level (NumLevel n)
| SetCustomEntry (s,n) -> keyword "in" ++ spc() ++ keyword "custom" ++ spc() ++ str s ++ (match n with None -> mt () | Some n -> pr_at_level (NumLevel n))
| SetAssoc LeftA -> keyword "left associativity"
| SetAssoc RightA -> keyword "right associativity"
| SetAssoc NonA -> keyword "no associativity"
| SetEntryType (x,typ) -> str x ++ spc() ++ pr_set_simple_entry_type typ
| SetOnlyPrinting -> keyword "only printing"
| SetOnlyParsing -> keyword "only parsing"
| SetFormat (TextFormat s) -> keyword "format " ++ pr_ast qs s)
let pr_syntax_modifiers = function
| [] -> mt()
| l -> spc() ++
hov 1 (str"(" ++ prlist_with_sep sep_v2 pr_syntax_modifier l ++ str")")
let pr_notation_declaration ntn_decl =
let open Vernacexpr in
let
{ ntn_decl_string = {CAst.loc;v=ntn};
ntn_decl_interp = c;
ntn_decl_modifiers = modifiers;
ntn_decl_scope = scopt } = ntn_decl in
qs ntn ++ spc () ++ str ":=" ++ spc ()
++ Flags.without_option Flags.beautify pr_constr c
++ pr_syntax_modifiers modifiers
++ pr_opt (fun sc -> spc () ++ str ":" ++ spc () ++ str sc) scopt
let pr_where_notation decl_ntn =
fnl () ++ keyword "where " ++ pr_notation_declaration decl_ntn
let pr_rec_definition { fname; univs; rec_order; binders; rtype; body_def; notations } =
let pr_pure_lconstr c = Flags.without_option Flags.beautify pr_lconstr c in
let annot = pr_guard_annot pr_lconstr_expr binders rec_order in
pr_ident_decl (fname,univs) ++ pr_binders_arg binders ++ annot
++ pr_type_option (fun c -> spc() ++ pr_lconstr_expr c) rtype
++ pr_opt (fun def -> str":=" ++ brk(1,2) ++ pr_pure_lconstr def) body_def
++ prlist pr_where_notation notations
let pr_statement head (idpl,(bl,c)) =
hov 2
(head ++ spc() ++ pr_ident_decl idpl ++ spc() ++
(match bl with [] -> mt() | _ -> pr_binders bl ++ spc()) ++
str":" ++ pr_spc_lconstr c)
let pr_rew_rule (ubinders, lhs, rhs) =
let binders = match ubinders with None -> mt()
| _ ->
pr_universe_decl ubinders ++ spc() ++ str"|-"
in
let pr_pure_lconstr c = Flags.without_option Flags.beautify pr_lconstr c in
binders ++ pr_pure_lconstr lhs ++ str"==>" ++ pr_pure_lconstr rhs
(**************************************)
(* Pretty printer for vernac commands *)
(**************************************)
let pr_constrarg c =
spc () ++ pr_constr c
let pr_lconstrarg c =
spc () ++ pr_lconstr c
let pr_intarg n = spc () ++ int n
let pr_vernac_attributes =
function
| [] -> mt ()
| flags -> str "#[" ++ prlist_with_sep pr_comma Attributes.pr_vernac_flag flags ++ str "]" ++ cut ()
let pr_oc coe ins = match coe, ins with
| NoCoercion, NoInstance -> str" :"
| AddCoercion, NoInstance -> str" :>"
| NoCoercion, BackInstance -> str" ::"
| AddCoercion, BackInstance -> str" ::>"
| _, BackInstanceWarning -> str" :>" (* remove this line at end of deprecation phase *)
let pr_record_field (x, { rfu_attrs = attr ; rfu_coercion = coe ; rfu_instance = ins ; rfu_priority = pri ; rfu_notation = ntn }) =
let prx = match x with
| AssumExpr (id,binders,t) ->
hov 1 (pr_vernac_attributes attr ++
pr_lname id ++
pr_binders_arg binders ++ spc() ++
pr_oc coe ins ++ spc() ++
pr_lconstr_expr t)
| DefExpr(id,binders,b,opt) -> (match opt with
| Some t ->
hov 1 (pr_vernac_attributes attr ++
pr_lname id ++
pr_binders_arg binders ++ spc() ++
pr_oc coe ins ++ spc() ++
pr_lconstr_expr t ++ str" :=" ++ pr_lconstr b)
| None ->
hov 1 (pr_vernac_attributes attr ++
pr_lname id ++ str" :=" ++ spc() ++
pr_lconstr b)) in
let prpri = match pri with None -> mt() | Some i -> str "| " ++ int i in
prx ++ prpri ++ prlist pr_where_notation ntn
let pr_record_decl c fs obinder =
pr_opt pr_lident c ++ pr_record "{" "}" pr_record_field fs ++
pr_opt (fun id -> str "as " ++ pr_lident id) obinder
let pr_printable = function
| PrintFullContext ->
keyword "Print All"
| PrintSectionContext s ->
keyword "Print Section" ++ spc() ++ Libnames.pr_qualid s
| PrintGrammar ent ->
keyword "Print Grammar" ++ spc() ++
prlist_with_sep spc str ent
| PrintCustomGrammar ent ->
keyword "Print Custom Grammar" ++ spc() ++ str ent
| PrintKeywords ->
keyword "Print Keywords"
| PrintLoadPath dir ->
keyword "Print LoadPath" ++ pr_opt DirPath.print dir
| PrintLibraries ->
keyword "Print Libraries"
| PrintMLLoadPath ->
keyword "Print ML Path"
| PrintMLModules ->
keyword "Print ML Modules"
| PrintDebugGC ->
keyword "Print ML GC"
| PrintGraph ->
keyword "Print Graph"
| PrintClasses ->
keyword "Print Classes"
| PrintTypeclasses ->
keyword "Print Typeclasses"
| PrintInstances qid ->
keyword "Print Instances" ++ spc () ++ pr_smart_global qid
| PrintCoercions ->
keyword "Print Coercions"
| PrintCoercionPaths (s,t) ->
keyword "Print Coercion Paths" ++ spc()
++ pr_class_rawexpr s ++ spc()
++ pr_class_rawexpr t
| PrintCanonicalConversions qids ->
keyword "Print Canonical Structures" ++ prlist pr_smart_global qids
| PrintTypingFlags ->
keyword "Print Typing Flags"
| PrintTables ->
keyword "Print Tables"
| PrintHintGoal ->
keyword "Print Hint"
| PrintHint qid ->
keyword "Print Hint" ++ spc () ++ pr_smart_global qid
| PrintHintDb ->
keyword "Print Hint *"
| PrintHintDbName s ->
keyword "Print HintDb" ++ spc () ++ str s
| PrintUniverses (b, g, fopt) ->
let cmd =
if b then "Print Sorted Universes"
else "Print Universes"
in
let pr_subgraph = prlist_with_sep spc pr_qualid in
keyword cmd ++ pr_opt pr_subgraph g ++ pr_opt str fopt
| PrintName (qid,udecl) ->
keyword "Print" ++ spc() ++ pr_smart_global qid ++ pr_full_univ_name_list udecl
| PrintModuleType qid ->
keyword "Print Module Type" ++ spc() ++ pr_qualid qid
| PrintModule qid ->
keyword "Print Module" ++ spc() ++ pr_qualid qid
| PrintInspect n ->
keyword "Inspect" ++ spc() ++ int n
| PrintScopes ->
keyword "Print Scopes"
| PrintScope s ->
keyword "Print Scope" ++ spc() ++ str s
| PrintVisibility s ->
keyword "Print Visibility" ++ pr_opt str s
| PrintAbout (qid,l,gopt) ->
pr_opt (fun g -> Goal_select.pr_goal_selector g ++ str ":"++ spc()) gopt
++ keyword "About" ++ spc() ++ pr_smart_global qid ++ pr_full_univ_name_list l
| PrintImplicit qid ->
keyword "Print Implicit" ++ spc() ++ pr_smart_global qid
(* spiwack: command printing all the axioms and section variables used in a
term *)
| PrintAssumptions (b, t, qid) ->
let cmd = match b, t with
| true, true -> "Print All Dependencies"
| true, false -> "Print Opaque Dependencies"
| false, true -> "Print Transparent Dependencies"
| false, false -> "Print Assumptions"
in
keyword cmd ++ spc() ++ pr_smart_global qid
| PrintNamespace dp ->
keyword "Print Namespace" ++ DirPath.print dp
| PrintStrategy None ->
keyword "Print Strategies"
| PrintStrategy (Some qid) ->
keyword "Print Strategy" ++ pr_smart_global qid
| PrintRegistered ->
keyword "Print Registered"
| PrintRegisteredSchemes ->
keyword "Print Registered Schemes"
| PrintNotation (Constrexpr.InConstrEntry, ntn_key) ->
keyword "Print Notation" ++ spc() ++ str ntn_key
| PrintNotation (Constrexpr.InCustomEntry ent, ntn_key) ->
keyword "Print Notation" ++ spc() ++ str ent ++ str ntn_key
let pr_using e =
let rec aux = function
| SsEmpty -> "()"
| SsType -> "(Type)"
| SsSingl { v=id } -> "("^Id.to_string id^")"
| SsCompl e -> "-" ^ aux e^""
| SsUnion(e1,e2) -> "("^aux e1 ^" + "^ aux e2^")"
| SsSubstr(e1,e2) -> "("^aux e1 ^" - "^ aux e2^")"
| SsFwdClose e -> "("^aux e^")*"
in Pp.str (aux e)
let pr_extend s cl =
let pr_arg a =
try pr_gen a
with Failure _ -> str "<error in " ++ str s.ext_entry ++ str ">" in
try
let rl = Egramml.get_extend_vernac_rule s in
let rec aux rl cl =
match rl, cl with
| Egramml.GramNonTerminal _ :: rl, arg :: cl -> pr_arg arg :: aux rl cl
| Egramml.GramTerminal s :: rl, cl -> str s :: aux rl cl
| [], [] -> []
| _ -> assert false in
hov 1 (pr_sequence identity (aux rl cl))
with Not_found ->
hov 1 (str "TODO(" ++ str s.ext_entry ++ spc () ++ prlist_with_sep sep pr_arg cl ++ str ")")
let pr_synpure_vernac_expr v =
let return = tag_vernac v in
match v with
(* Proof management *)
| VernacAbortAll ->
return (keyword "Abort All")
| VernacRestart ->
return (keyword "Restart")
| VernacUnfocus ->
return (keyword "Unfocus")
| VernacUnfocused ->
return (keyword "Unfocused")
| VernacAbort ->
return (keyword "Abort")
| VernacUndo i ->
return (
if Int.equal i 1 then keyword "Undo" else keyword "Undo" ++ pr_intarg i
)
| VernacUndoTo i ->
return (keyword "Undo" ++ spc() ++ keyword "To" ++ pr_intarg i)
| VernacFocus i ->
return (keyword "Focus" ++ pr_opt int i)
| VernacShow s ->
let pr_goal_reference = function
| OpenSubgoals -> mt ()
| NthGoal n -> spc () ++ int n
| GoalId id -> spc () ++ pr_id id
in
let pr_showable = function
| ShowGoal n -> keyword "Show" ++ pr_goal_reference n
| ShowProof -> keyword "Show Proof"
| ShowExistentials -> keyword "Show Existentials"
| ShowUniverses -> keyword "Show Universes"
| ShowProofNames -> keyword "Show Conjectures"
| ShowIntros b -> keyword "Show " ++ (if b then keyword "Intros" else keyword "Intro")
| ShowMatch id -> keyword "Show Match " ++ pr_qualid id
in
return (pr_showable s)
| VernacCheckGuard ->
return (keyword "Guarded")
| VernacValidateProof -> return (keyword "Validate Proof")
(* Resetting *)
| VernacResetName id ->
return (keyword "Reset" ++ spc() ++ pr_lident id)
| VernacResetInitial ->
return (keyword "Reset Initial")
| VernacBack i ->
return (
if Int.equal i 1 then keyword "Back" else keyword "Back" ++ pr_intarg i
)
(* Syntax *)
| VernacOpenCloseScope (opening,sc) ->
return (
keyword (if opening then "Open " else "Close ") ++
keyword "Scope" ++ spc() ++ str sc
)
| VernacDeclareScope sc ->
return (
keyword "Declare Scope" ++ spc () ++ str sc
)
| VernacDelimiters (sc,Some key) ->
return (
keyword "Delimit Scope" ++ spc () ++ str sc ++
spc() ++ keyword "with" ++ spc () ++ str key
)
| VernacDelimiters (sc, None) ->
return (
keyword "Undelimit Scope" ++ spc () ++ str sc
)
| VernacBindScope (sc,cll) ->
return (
keyword "Bind Scope" ++ spc () ++ str sc ++
spc() ++ keyword "with" ++ spc () ++ prlist_with_sep spc pr_class_rawexpr cll
)
| VernacEnableNotation (on,rule,interp,flags,scope) ->
let pr_flag = function
| EnableNotationEntry CAst.{v=InConstrEntry} -> str "in constr"
| EnableNotationEntry CAst.{v=InCustomEntry s} -> str "in custom " ++ str s
| EnableNotationOnly OnlyParsing -> str "only parsing"
| EnableNotationOnly OnlyPrinting -> str "only printing"
| EnableNotationOnly ParsingAndPrinting -> assert false
| EnableNotationAll -> str "all" in
let pr_flags = function
| [] -> mt ()
| l -> str "(" ++ prlist_with_sep pr_comma pr_flag l ++ str ")" in
let pr_rule = match rule with
| None -> mt ()
| Some (Inl ntn) -> quote (str ntn)
| Some (Inr abbrev) -> pr_abbreviation pr_qualid abbrev in
let pr_opt_scope = function
| None -> mt ()
| Some (NotationInScope s) -> spc () ++ str ": " ++ str s
| Some LastLonelyNotation -> str ":" ++ spc () ++ str "none" in
let pp = pr_rule ++ pr_flags flags ++ pr_opt_scope scope in
return (
keyword (if on then "Enable Notation " else "Disable Notation ") ++ pp
)
(* Gallina *)
| VernacDefinition ((discharge,kind),id,b) -> (* A verifier... *)
let isgoal = Name.is_anonymous (fst id).v in
let pr_def_token =
keyword (
if isgoal
then "Goal"
else string_of_definition_object_kind kind)
in
let pr_reduce = function
| None -> mt()
| Some r ->
keyword "Eval" ++ spc() ++
pr_red_expr r ++
keyword " in" ++ spc()
in
let pr_def_body = match b with
| DefineBody (bl,red,body,d) ->
let ty = match d with
| None -> mt()
| Some ty -> spc() ++ str":" ++ pr_spc_lconstr ty
in
pr_binders_arg bl ++ ty ++ str " :=" ++ spc() ++ pr_reduce red ++ pr_lconstr body
| ProveBody (bl,t) ->
let typ u = if isgoal then (assert (bl = []); u) else (str" :" ++ u) in
pr_binders_arg bl ++ typ (pr_spc_lconstr t)
in
return (
hov 2 (
pr_def_token
++ (if isgoal then mt() else spc() ++ pr_lname_decl id)
++ pr_def_body)
)
| VernacStartTheoremProof (ki,l) ->
return (
hov 1 (pr_statement (pr_thm_token ki) (List.hd l) ++
prlist (pr_statement (spc () ++ keyword "with")) (List.tl l))
)
| VernacEndProof Admitted ->
return (keyword "Admitted")
| VernacEndProof (Proved (opac,o)) -> return (
match o with
| None -> (match opac with
| Transparent -> keyword "Defined"
| Opaque -> keyword "Qed")
| Some id -> (if opac <> Transparent then keyword "Save" else keyword "Defined") ++ spc() ++ pr_lident id
)
| VernacExactProof c ->
return (hov 2 (keyword "Proof" ++ pr_lconstrarg c))
| VernacAssumption ((discharge,kind),t,l) ->
let n = List.length (List.flatten (List.map fst (List.map snd l))) in
let pr_params (c, (xl, t)) =
hov 2 (prlist_with_sep sep pr_ident_decl xl ++ spc() ++
str(match c with AddCoercion -> ":>" | NoCoercion -> ":") ++ spc() ++ pr_lconstr_expr t) in
let assumptions = prlist_with_sep spc (fun p -> hov 1 (str "(" ++ pr_params p ++ str ")")) l in
return (hov 2 (pr_assumption_token (n > 1) discharge kind ++
pr_non_empty_arg pr_assumption_inline t ++ spc() ++ assumptions))
| VernacSymbol l ->
let n = List.length (List.flatten (List.map fst (List.map snd l))) in
let pr_params (c, (xl, t)) =
hov 2 (prlist_with_sep sep pr_ident_decl xl ++ spc() ++
str(match c with AddCoercion -> ":>" | NoCoercion -> ":") ++ spc() ++ pr_lconstr_expr t) in
let assumptions = prlist_with_sep spc (fun p -> hov 1 (str "(" ++ pr_params p ++ str ")")) l in
return (hov 2 (keyword (if (n > 1) then "Symbols" else "Symbol") ++ spc() ++ assumptions))
| VernacInductive (f,l) ->
let pr_constructor ((attr,coe,ins),(id,c)) =
hov 2 (pr_vernac_attributes attr ++ pr_lident id ++ pr_oc coe ins ++
Flags.without_option Flags.beautify pr_spc_lconstr c)
in
let pr_constructor_list l = match l with
| Constructors [] -> mt()
| Constructors l ->
let fst_sep = match l with [_] -> " " | _ -> " | " in
pr_com_at (begin_of_inductive l) ++
fnl() ++ str fst_sep ++
prlist_with_sep (fun _ -> fnl() ++ str" | ") pr_constructor l
| RecordDecl (c,fs,obinder) ->
pr_record_decl c fs obinder
in
let pr_oneind key (((coe,iddecl),(indupar,indpar),s,lc),ntn) =
hov 0 (
str key ++ spc() ++
str(match coe with AddCoercion -> "> " | NoCoercion -> "") ++ pr_cumul_ident_decl iddecl ++
pr_and_type_binders_arg indupar ++
pr_opt (fun p -> str "|" ++ spc() ++ pr_and_type_binders_arg p) indpar ++
pr_opt (fun s -> str":" ++ spc() ++ pr_lconstr_expr s) s ++
str" :=") ++ pr_constructor_list lc ++
prlist pr_where_notation ntn
in
let kind =
match f with
| Record -> "Record" | Structure -> "Structure"
| Inductive_kw -> "Inductive" | CoInductive -> "CoInductive"
| Class _ -> "Class" | Variant -> "Variant"
in
return (
hov 1 (pr_oneind kind (List.hd l)) ++
(prlist (fun ind -> fnl() ++ hov 1 (pr_oneind "with" ind)) (List.tl l))
)
| VernacFixpoint (local, recs) ->
let local = match local with
| DoDischarge -> "Let "
| NoDischarge -> ""
in
return (
hov 0 (str local ++ keyword "Fixpoint" ++ spc () ++
prlist_with_sep (fun _ -> fnl () ++ keyword "with"
++ spc ()) pr_rec_definition recs)
)
| VernacCoFixpoint (local, corecs) ->
let local = match local with
| DoDischarge -> keyword "Let" ++ spc ()
| NoDischarge -> str ""
in
let pr_onecorec {fname; univs; binders; rtype; body_def; notations } =
pr_ident_decl (fname,univs) ++ spc() ++ pr_binders binders ++ spc() ++ str":" ++
spc() ++ pr_lconstr_expr rtype ++
pr_opt (fun def -> str":=" ++ brk(1,2) ++ pr_lconstr def) body_def ++
prlist pr_where_notation notations
in
return (
hov 0 (local ++ keyword "CoFixpoint" ++ spc() ++
prlist_with_sep (fun _ -> fnl() ++ keyword "with" ++ spc ()) pr_onecorec corecs)
)
| VernacScheme l ->
return (
hov 2 (keyword "Scheme" ++ spc() ++
prlist_with_sep (fun _ -> fnl() ++ keyword "with" ++ spc ()) pr_onescheme l)
)
| VernacSchemeEquality (sch,id) ->
return (
hov 2 (keyword "Scheme " ++ pr_equality_scheme_type sch id)
)
| VernacCombinedScheme (id, l) ->
return (
hov 2 (keyword "Combined Scheme" ++ spc() ++
pr_lident id ++ spc() ++ keyword "from" ++ spc() ++
prlist_with_sep (fun _ -> fnl() ++ str", ") pr_lident l)
)
| VernacUniverse v ->
return (
hov 2 (keyword "Universe" ++ spc () ++
prlist_with_sep (fun _ -> str",") pr_lident v)
)
| VernacConstraint v ->
return (
hov 2 (keyword "Constraint" ++ spc () ++
prlist_with_sep (fun _ -> str",") pr_uconstraint v)
)
(* Gallina extensions *)
| VernacNameSectionHypSet (id,set) ->
return (hov 2 (keyword "Collection" ++ spc() ++ pr_lident id ++ spc()++
str ":="++spc()++pr_using set))
| VernacCanonical q ->
return (
keyword "Canonical Structure" ++ spc() ++ pr_smart_global q
)
| VernacCoercion (id,Some(c1,c2)) ->
return (
hov 1 (
keyword "Coercion" ++ spc() ++
pr_smart_global id ++ spc() ++ str":" ++ spc() ++ pr_class_rawexpr c1 ++
spc() ++ str">->" ++ spc() ++ pr_class_rawexpr c2)
)
| VernacCoercion (id,None) ->
return (
hov 1 (
keyword "Coercion" ++ spc() ++
pr_smart_global id)
)
| VernacIdentityCoercion (id,c1,c2) ->
return (
hov 1 (
keyword "Identity Coercion" ++ spc() ++ pr_lident id ++
spc() ++ str":" ++ spc() ++ pr_class_rawexpr c1 ++ spc() ++ str">->" ++
spc() ++ pr_class_rawexpr c2)
)
| VernacInstance (instid, sup, cl, props, info) ->
return (