Debian Codegraph @

vernac/ppvernac.ml

raw symbols SCIP
1 (************************************************************************)
2 (* * The Rocq Prover / The Rocq Development Team *)
3 (* v * Copyright INRIA, CNRS and contributors *)
4 (* <O___,, * (see version control and CREDITS file for authors & dates) *)
5 (* \VV/ **************************************************************)
6 (* // * This file is distributed under the terms of the *)
7 (* * GNU Lesser General Public License Version 2.1 *)
8 (* * (see LICENSE file for the text of the license) *)
9 (************************************************************************)
10
11 open Pp
12 open Names
13
14 open CErrors
15 open Util
16 open CAst
17
18 open Extend
19 open Constrexpr
20 open Vernacexpr
21 open Declaremods
22 open Pputils
23
24 open Ppconstr
25
26 let do_not_tag _ x = x
27 let tag_keyword = do_not_tag ()
28 let tag_vernac = do_not_tag
29
30 let keyword s = tag_keyword (str s)
31
32 let pr_smart_global = Pputils.pr_or_by_notation pr_qualid
33
34 let pr_in_global_env f c : Pp.t =
35 let env = Global.env () in
36 let sigma = Evd.from_env env in
37 f env sigma c
38
39 let pr_in_global_env_with_ppflags f c : Pp.t =
40 let flags = Ppconstr.current_flags () in
41 pr_in_global_env (f ~flags) c
42
43 (* when not !Flags.beautify_file these just ignore the env/sigma *)
44 let pr_constr_expr = pr_in_global_env_with_ppflags pr_constr_expr
45 let pr_lconstr_expr = pr_in_global_env_with_ppflags pr_lconstr_expr
46 let pr_binders = pr_in_global_env_with_ppflags pr_binders
47 let pr_constr_pattern_expr = pr_in_global_env_with_ppflags pr_constr_pattern_expr
48 let pr_user_red_expr = pr_in_global_env Redexpr.pr_raw_user_red_expr
49
50 (* In principle this may use the env/sigma, in practice not sure if it
51 does except through pr_constr_expr in beautify mode. *)
52 let pr_gen = pr_in_global_env (Pputils.pr_raw_generic ?level:None)
53 let pr_gentac = pr_in_global_env (Gentactic.print_raw ?level:None)
54
55 (* No direct Global.env or pr_in_global_env use after this *)
56
57 let pr_constr = pr_constr_expr
58 let pr_lconstr = pr_lconstr_expr
59 let pr_spc_lconstr =
60 pr_sep_com spc @@ pr_lconstr_expr
61
62 let pr_red_expr =
63 Ppred.pr_red_expr
64 (pr_constr_expr, pr_lconstr_expr, pr_smart_global, pr_constr_expr, pr_or_var int, pr_user_red_expr)
65 keyword
66
67 let pr_uconstraint (l, d, r) =
68 pr_sort_name_expr l ++ spc () ++ Univ.UnivConstraint.pr_kind d ++ spc () ++
69 pr_sort_name_expr r
70
71 let pr_elim_constraint (l, d, r) =
72 pr_quality_expr l ++ spc () ++ Sorts.ElimConstraint.pr_kind d ++ spc () ++
73 pr_quality_expr r
74
75 let pr_pconstraint = function
76 | UnivCst (l,d,r as c) -> pr_uconstraint c
77 | ElimCst (l,d,r as c) -> pr_elim_constraint c
78
79 let pr_full_univ_name_list = function
80 | None -> mt()
81 | Some (ql, ul) ->
82 str "@{" ++ prlist_with_sep spc pr_lname ql ++
83 (if List.is_empty ql then mt() else strbrk " ; ") ++
84 prlist_with_sep spc pr_lname ul ++ str "}"
85
86 let pr_variance_lident (lid,v) =
87 let v = Option.cata UVars.Variance.pr (mt()) v in
88 v ++ pr_lident lid
89
90 let pr_univ_decl_qualities l extensible =
91 (* "extensible" not really supported in syntax currently *)
92 if List.is_empty l then mt()
93 else prlist_with_sep spc pr_lident l ++ strbrk " ; "
94
95 let pr_univ_decl_instance l extensible =
96 prlist_with_sep spc pr_lident l ++
97 (if extensible then str"+" else mt ())
98
99 let pr_cumul_univ_decl_instance l extensible =
100 prlist_with_sep spc pr_variance_lident l ++
101 (if extensible then str"+" else mt ())
102
103 let pr_univ_decl_constraints elims univs extensible =
104 if List.is_empty elims && List.is_empty univs && extensible then mt ()
105 else pr_spcbar () ++ prlist_with_sep pr_comma pr_elim_constraint elims ++
106 prlist_with_sep pr_comma pr_uconstraint univs ++
107 (if extensible then str"+" else mt())
108
109 let pr_universe_decl l =
110 let open UState in
111 match l with
112 | None -> mt ()
113 | Some l ->
114 str"@{" ++
115 pr_univ_decl_qualities l.univdecl_qualities l.univdecl_extensible_qualities ++
116 pr_univ_decl_instance l.univdecl_instance l.univdecl_extensible_instance ++
117 pr_univ_decl_constraints l.univdecl_elim_constraints l.univdecl_univ_constraints l.univdecl_extensible_constraints ++
118 str "}"
119
120 let pr_cumul_univ_decl l =
121 let open UState in
122 match l with
123 | None -> mt ()
124 | Some l ->
125 str"@{" ++
126 pr_univ_decl_qualities l.univdecl_qualities l.univdecl_extensible_qualities ++
127 pr_cumul_univ_decl_instance l.univdecl_instance l.univdecl_extensible_instance ++
128 pr_univ_decl_constraints l.univdecl_elim_constraints l.univdecl_univ_constraints l.univdecl_extensible_constraints ++
129 str "}"
130
131 let pr_ident_decl (lid, l) =
132 pr_lident lid ++ pr_universe_decl l
133
134 let pr_cumul_ident_decl (lid, l) =
135 pr_lident lid ++ pr_cumul_univ_decl l
136
137 let string_of_fqid fqid =
138 String.concat "." (List.map Id.to_string fqid)
139
140 let pr_fqid fqid = str (string_of_fqid fqid)
141
142 let pr_lfqid {CAst.loc;v=fqid} =
143 match loc with
144 | None -> pr_fqid fqid
145 | Some loc -> let (b,_) = Loc.unloc loc in
146 pr_located pr_fqid @@ Loc.tag ~loc:(Loc.make_loc (b,b + String.length (string_of_fqid fqid))) fqid
147
148 let pr_lname_decl (n, u) =
149 pr_lname n ++ pr_universe_decl u
150
151 let pr_ltac_ref = Libnames.pr_qualid
152
153 let pr_module = Libnames.pr_qualid
154
155 let pr_import_cats = function
156 | None -> mt()
157 | Some {negative;import_cats=cats} ->
158 (if negative then str "-" else mt()) ++
159 str "(" ++
160 prlist_with_sep (fun () -> str ",") (fun x -> str x.v) cats ++
161 str ")"
162
163 let pr_one_import_filter_name (q,etc) =
164 Libnames.pr_qualid q ++ if etc then str "(..)" else mt()
165
166 let pr_import_module (m,f) =
167 Libnames.pr_qualid m ++ match f with
168 | ImportAll -> mt()
169 | ImportNames ns -> surround (prlist_with_sep pr_comma pr_one_import_filter_name ns)
170
171 let sep_end = function
172 | VernacSynPure (VernacBullet _ | VernacSubproof _ | VernacEndSubproof) -> mt()
173 | _ -> str"."
174
175 let sep = fun _ -> spc()
176 let sep_v2 = fun _ -> str"," ++ spc()
177
178 let string_of_theorem_kind = let open Decls in function
179 | Theorem -> "Theorem"
180 | Lemma -> "Lemma"
181 | Fact -> "Fact"
182 | Remark -> "Remark"
183 | Property -> "Property"
184 | Proposition -> "Proposition"
185 | Corollary -> "Corollary"
186
187 let string_of_definition_object_kind = let open Decls in function
188 | Definition -> "Definition"
189 | Example -> "Example"
190 | Coercion -> "Coercion"
191 | SubClass -> "SubClass"
192 | CanonicalStructure -> "Canonical Structure"
193 | Instance -> "Instance"
194 | Let -> "Let"
195 | LetContext -> CErrors.anomaly (Pp.str "Bound to Context.")
196 | (StructureComponent|Scheme|CoFixpoint|Fixpoint|IdentityCoercion|Method) ->
197 CErrors.anomaly (Pp.str "Internal definition kind.")
198
199 let string_of_assumption_kind = let open Decls in function
200 | Definitional -> "Parameter"
201 | Logical -> "Axiom"
202 | Conjectural -> "Conjecture"
203 | Context -> "Context"
204
205 let string_of_logical_kind = let open Decls in function
206 | IsAssumption k -> string_of_assumption_kind k
207 | IsDefinition k -> string_of_definition_object_kind k
208 | IsProof k -> string_of_theorem_kind k
209 | IsPrimitive -> "Primitive"
210 | IsSymbol -> "Symbol"
211
212 let pr_notation_entry prcustom = function
213 | InConstrEntry -> keyword "constr"
214 | InCustomEntry s -> keyword "custom" ++ spc () ++ prcustom s
215
216 let pr_abbreviation pr (ids, c) =
217 pr c ++ spc () ++ prlist_with_sep spc pr_id ids
218
219 let pr_at_level = function
220 | NumLevel n -> spc () ++ keyword "at" ++ spc () ++ keyword "level" ++ spc () ++ int n
221 | NextLevel -> spc () ++ keyword "at" ++ spc () ++ keyword "next" ++ spc () ++ keyword "level"
222 | DefaultLevel -> mt ()
223
224 let level_of_pattern_level = function None -> DefaultLevel | Some n -> NumLevel n
225
226 let pr_constr_as_binder_kind = let open Notation_term in function
227 | AsIdent -> spc () ++ keyword "as ident"
228 | AsName -> spc () ++ keyword "as name"
229 | AsAnyPattern -> spc () ++ keyword "as pattern"
230 | AsStrictPattern -> spc () ++ keyword "as strict pattern"
231
232 let pr_strict b = if b then str "strict " else mt ()
233
234 let pr_set_entry_type prcustom pr = function
235 | ETIdent -> str"ident"
236 | ETName -> str"name"
237 | ETGlobal -> str"global"
238 | ETPattern (b,n) -> pr_strict b ++ str"pattern" ++ pr_at_level (level_of_pattern_level n)
239 | ETConstr (s,bko,lev) -> pr_notation_entry prcustom s ++ pr lev ++ pr_opt pr_constr_as_binder_kind bko
240 | ETBigint -> str "bigint"
241 | ETBinder true -> str "binder"
242 | ETBinder false -> str "closed binder"
243
244 let pr_set_simple_entry_type =
245 pr_set_entry_type pr_qualid pr_at_level
246
247 let pr_comment pr_c = function
248 | CommentConstr c -> pr_c c
249 | CommentString s -> qs s
250 | CommentInt n -> int n
251
252 let pr_in_out_modules = function
253 | SearchInside l -> spc() ++ keyword "inside" ++ spc() ++ prlist_with_sep sep pr_module l
254 | SearchOutside [] -> mt()
255 | SearchOutside l -> spc() ++ keyword "outside" ++ spc() ++ prlist_with_sep sep pr_module l
256
257 let pr_search_where = function
258 | Anywhere, false -> mt ()
259 | Anywhere, true -> str "head:"
260 | InHyp, true -> str "headhyp:"
261 | InHyp, false -> str "hyp:"
262 | InConcl, true -> str "headconcl:"
263 | InConcl, false -> str "concl:"
264
265 let pr_delimiter_depth = function
266 | DelimOnlyTmpScope -> str "%_"
267 | DelimUnboundedScope -> str "%"
268
269 let pr_scope_delimiter (d, sc) = pr_delimiter_depth d ++ str sc
270
271 let pr_search_item = function
272 | SearchSubPattern (where,p) ->
273 pr_search_where where ++ pr_constr_pattern_expr p
274 | SearchString (where,s,sc) -> pr_search_where where ++ qs s ++ pr_opt pr_scope_delimiter sc
275 | SearchKind kind -> str "is:" ++ str (string_of_logical_kind kind)
276
277 let rec pr_search_request = function
278 | SearchLiteral a -> pr_search_item a
279 | SearchDisjConj l -> str "[" ++ prlist_with_sep spc (prlist_with_sep pr_bar pr_search_default) l ++ str "]"
280
281 and pr_search_default (b, s) =
282 (if b then mt() else str "-") ++ pr_search_request s
283
284 let pr_search a gopt b pr_p =
285 pr_opt (fun g -> Goal_select.pr_goal_selector g ++ str ":"++ spc()) gopt
286 ++
287 match a with
288 | SearchPattern c -> keyword "SearchPattern" ++ spc() ++ pr_p c ++ pr_in_out_modules b
289 | SearchRewrite c -> keyword "SearchRewrite" ++ spc() ++ pr_p c ++ pr_in_out_modules b
290 | Search sl ->
291 keyword "Search" ++ spc() ++ prlist_with_sep spc pr_search_default sl ++ pr_in_out_modules b
292
293 let pr_option_ref_value = function
294 | Goptions.QualidRefValue id -> pr_qualid id
295 | Goptions.StringRefValue s -> qs s
296
297 let pr_printoption table b =
298 prlist_with_sep spc str table ++
299 pr_opt (prlist_with_sep sep pr_option_ref_value) b
300
301 let pr_set_option a b =
302 pr_printoption a None ++ (match b with
303 | OptionUnset | OptionSetTrue -> mt()
304 | OptionSetInt n -> spc() ++ int n
305 | OptionSetString s -> spc() ++ quote (str s))
306
307 let pr_opt_hintbases l = match l with
308 | [] -> mt()
309 | _ as z -> str":" ++ spc() ++ prlist_with_sep sep str z
310
311 let pr_reference_or_constr pr_c = function
312 | HintsReference r -> pr_qualid r
313 | HintsConstr c -> pr_c c
314
315 let pr_hint_mode = let open Hints in function
316 | ModeInput -> str"+"
317 | ModeNoHeadEvar -> str"!"
318 | ModeOutput -> str"-"
319
320 let pr_hint_info pr_pat { Typeclasses.hint_priority = pri; hint_pattern = pat } =
321 pr_opt (fun x -> str"|" ++ int x) pri ++
322 pr_opt (fun y -> (if Option.is_empty pri then str"| " else mt()) ++ pr_pat y) pat
323
324 let pr_hints db h pr_c pr_pat =
325 let opth = pr_opt_hintbases db in
326 let pph =
327 let open Hints in
328 match h with
329 | HintsResolve l ->
330 keyword "Resolve " ++ prlist_with_sep sep
331 (fun (info, _, c) -> pr_reference_or_constr pr_c c ++ pr_hint_info pr_pat info)
332 l
333 | HintsResolveIFF (l2r, l, n) ->
334 keyword "Resolve " ++ str (if l2r then "->" else "<-")
335 ++ prlist_with_sep sep pr_qualid l
336 | HintsImmediate l ->
337 keyword "Immediate" ++ spc() ++
338 prlist_with_sep sep (fun c -> pr_reference_or_constr pr_c c) l
339 | HintsUnfold l ->
340 keyword "Unfold" ++ spc () ++ prlist_with_sep sep pr_qualid l
341 | HintsTransparency (l, b) ->
342 keyword (if b then "Transparent" else "Opaque")
343 ++ spc ()
344 ++ (match l with
345 | HintsVariables -> keyword "Variables"
346 | HintsConstants -> keyword "Constants"
347 | HintsProjections -> keyword "Projections"
348 | HintsReferences l -> prlist_with_sep sep pr_qualid l)
349 | HintsMode (m, l) ->
350 keyword "Mode"
351 ++ spc ()
352 ++ pr_qualid m ++ spc() ++
353 prlist_with_sep spc pr_hint_mode l
354 | HintsConstructors c ->
355 keyword "Constructors"
356 ++ spc() ++ prlist_with_sep spc pr_qualid c
357 | HintsExtern (n,c,tac) ->
358 let pat = match c with None -> mt () | Some pat -> pr_pat pat in
359 keyword "Extern" ++ spc() ++ int n ++ spc() ++ pat ++ str" =>" ++
360 spc() ++ pr_gentac tac
361 in
362 hov 2 (keyword "Hint "++ pph ++ opth)
363
364 let pr_with_declaration pr_c = function
365 | CWith_Definition (id,udecl,c) ->
366 let p = pr_c c in
367 keyword "Definition" ++ spc() ++ pr_lfqid id ++ pr_universe_decl udecl ++ str" := " ++ p
368 | CWith_Module (id,qid) ->
369 keyword "Module" ++ spc() ++ pr_lfqid id ++ str" := " ++
370 pr_qualid qid
371
372 let rec pr_module_ast leading_space pr_c = function
373 | { loc ; v = CMident qid } ->
374 if leading_space then
375 spc () ++ pr_located pr_qualid (loc, qid)
376 else
377 pr_located pr_qualid (loc,qid)
378 | { v = CMwith (mty,decl) } ->
379 let m = pr_module_ast leading_space pr_c mty in
380 let p = pr_with_declaration pr_c decl in
381 m ++ spc() ++ keyword "with" ++ spc() ++ p
382 | { v = CMapply (me1, me2 ) } ->
383 pr_module_ast leading_space pr_c me1 ++ spc() ++ pr_located pr_qualid (me2.loc, me2)
384
385 let pr_inline = function
386 | DefaultInline -> mt ()
387 | NoInline -> str "[no inline]"
388 | InlineAt i -> str "[inline at level " ++ int i ++ str "]"
389
390 let pr_assumption_inline = function
391 | DefaultInline -> str "Inline"
392 | NoInline -> mt ()
393 | InlineAt i -> str "Inline(" ++ int i ++ str ")"
394
395 let pr_module_ast_inl leading_space pr_c (mast,inl) =
396 pr_module_ast leading_space pr_c mast ++ pr_inline inl
397
398 let pr_of_module_type prc = function
399 | Enforce mty -> str ":" ++ pr_module_ast_inl true prc mty
400 | Check mtys ->
401 prlist_strict (fun m -> str "<:" ++ pr_module_ast_inl true prc m) mtys
402
403 let pr_export_flag = function
404 | Export -> keyword "Export"
405 | Import -> keyword "Import"
406
407 let pr_export_with_cats (export,cats) =
408 pr_export_flag export ++ pr_import_cats cats
409
410 let pr_require_token = function
411 | Some export ->
412 pr_export_with_cats export ++ spc ()
413 | None -> mt()
414
415 let pr_module_vardecls pr_c (export,idl,(mty,inl)) =
416 let m = pr_module_ast true pr_c mty in
417 spc() ++
418 hov 1 (str"(" ++ pr_require_token export ++
419 prlist_with_sep spc pr_lident idl ++ str":" ++ m ++ str")")
420
421 let pr_module_binders l pr_c =
422 prlist_strict (pr_module_vardecls pr_c) l
423
424 let pr_type_option pr_c = function
425 | { v = CHole (Some GNamedHole _) } as c -> brk(0,2) ++ str" :" ++ pr_c c
426 | { v = CHole _ } -> mt()
427 | _ as c -> brk(0,2) ++ str" :" ++ pr_c c
428
429 let pr_binders_arg =
430 pr_non_empty_arg @@ pr_binders
431
432 let pr_and_type_binders_arg bl =
433 pr_binders_arg bl
434
435 let pr_onescheme (idop, {sch_type; sch_qualid; sch_sort}) =
436 let str_identifier = match idop with
437 | Some id -> pr_lident id ++ str " :="
438 | None -> str "" in
439 let str_scheme = match sch_type with
440 | SchemeInduction -> keyword "Induction for"
441 | SchemeMinimality -> keyword "Minimality for"
442 | SchemeElimination -> keyword "Elimination for"
443 | SchemeCase -> keyword "Case for" in
444 hov 0 str_identifier ++ spc () ++ hov 0 (str_scheme ++ spc() ++ pr_smart_global sch_qualid)
445 ++ spc () ++ hov 0 (keyword "Sort" ++ spc() ++ UnivGen.QualityOrSet.pr Sorts.QVar.raw_pr sch_sort)
446
447 let pr_equality_scheme_type sch id =
448 let str_scheme = match sch with
449 | SchemeBooleanEquality -> keyword "Boolean Equality"
450 | SchemeEquality -> keyword "Equality"
451 | SchemeRewriting -> keyword "Rewriting"
452 in
453 hov 0 (str_scheme ++ str " for" ++ spc() ++ pr_smart_global id)
454
455 let begin_of_inductive = function
456 | [] -> 0
457 | (_,({loc},_))::_ -> Option.cata (fun loc -> fst (Loc.unloc loc)) 0 loc
458
459 let pr_class_rawexpr = function
460 | FunClass -> keyword "Funclass"
461 | SortClass -> keyword "Sortclass"
462 | RefClass qid -> pr_smart_global qid
463
464 let pr_assumption_token many discharge kind =
465 match discharge, kind with
466 | (NoDischarge,Decls.Logical) ->
467 keyword (if many then "Axioms" else "Axiom")
468 | (NoDischarge,Decls.Definitional) ->
469 keyword (if many then "Parameters" else "Parameter")
470 | (NoDischarge,Decls.Conjectural) -> str"Conjecture"
471 | (DoDischarge,Decls.Logical) ->
472 keyword (if many then "Hypotheses" else "Hypothesis")
473 | (DoDischarge,Decls.Definitional) ->
474 keyword (if many then "Variables" else "Variable")
475 | (DoDischarge,Decls.Conjectural) ->
476 anomaly (Pp.str "Don't know how to beautify a local conjecture.")
477 | (_,Decls.Context) ->
478 anomaly (Pp.str "Context is used only internally.")
479
480 let pr_params pr_c (xl,(c,t)) =
481 hov 2 (prlist_with_sep sep pr_lident xl ++ spc() ++
482 (if c then str":>" else str":" ++
483 spc() ++ pr_c t))
484
485 let rec factorize = function
486 | [] -> []
487 | (c,(idl,t))::l ->
488 match factorize l with
489 | (xl,((c', t') as r))::l'
490 when (c : bool) == c' && (=) t t' ->
491 (* FIXME: we need equality on constr_expr *)
492 (idl@xl,r)::l'
493 | l' -> (idl,(c,t))::l'
494
495 let pr_ne_params_list pr_c l =
496 match factorize l with
497 | [p] -> pr_params pr_c p
498 | l ->
499 prlist_with_sep spc
500 (fun p -> hov 1 (str "(" ++ pr_params pr_c p ++ str ")")) l
501
502 (*
503 prlist_with_sep pr_semicolon (pr_params pr_c)
504 *)
505
506 let pr_thm_token k = keyword (string_of_theorem_kind k)
507
508 let pr_syntax_modifier = let open Gramlib.Gramext in CAst.with_val (function
509 | SetItemLevel (l,bko,n) ->
510 prlist_with_sep sep_v2 str l ++ spc () ++ pr_at_level n ++
511 pr_opt pr_constr_as_binder_kind bko
512 | SetItemScope (l,s) ->
513 prlist_with_sep sep_v2 str l ++ spc () ++ str"in scope" ++ str s
514 | SetLevel n -> pr_at_level (NumLevel n)
515 | SetCustomEntry (s,n) -> keyword "in" ++ spc() ++ keyword "custom" ++ spc() ++ pr_qualid s ++ (match n with None -> mt () | Some n -> pr_at_level (NumLevel n))
516 | SetAssoc BothA -> assert false
517 | SetAssoc LeftA -> keyword "left associativity"
518 | SetAssoc RightA -> keyword "right associativity"
519 | SetAssoc NonA -> keyword "no associativity"
520 | SetEntryType (x,typ) -> str x ++ spc() ++ pr_set_simple_entry_type typ
521 | SetOnlyPrinting -> keyword "only printing"
522 | SetOnlyParsing -> keyword "only parsing"
523 | SetFormat (TextFormat s) -> keyword "format " ++ pr_ast qs s)
524
525 let pr_syntax_modifiers = function
526 | [] -> mt()
527 | l -> spc() ++
528 hov 1 (str"(" ++ prlist_with_sep sep_v2 pr_syntax_modifier l ++ str")")
529
530 let pr_notation_declaration ntn_decl =
531 let open Vernacexpr in
532 let
533 { ntn_decl_string = {CAst.loc;v=ntn};
534 ntn_decl_interp = c;
535 ntn_decl_modifiers = modifiers;
536 ntn_decl_scope = scopt } = ntn_decl in
537 qs ntn ++ spc () ++ str ":=" ++ spc ()
538 ++ Flags.without_option Flags.beautify pr_constr c
539 ++ pr_syntax_modifiers modifiers
540 ++ pr_opt (fun sc -> spc () ++ str ":" ++ spc () ++ str sc) scopt
541
542 let pr_where_notation decl_ntn =
543 fnl () ++ keyword "where " ++ pr_notation_declaration decl_ntn
544
545 let pr_rec_definition (rec_order, { fname; univs; binders; rtype; body_def; notations }) =
546 let pr_pure_lconstr c = Flags.without_option Flags.beautify pr_lconstr c in
547 let annot = pr_guard_annot pr_lconstr_expr binders rec_order in
548 pr_ident_decl (fname,univs) ++ pr_binders_arg binders ++ annot
549 ++ pr_type_option (fun c -> spc() ++ pr_lconstr_expr c) rtype
550 ++ pr_opt (fun def -> str":=" ++ brk(1,2) ++ pr_pure_lconstr def) body_def
551 ++ prlist pr_where_notation notations
552
553 let pr_statement head (idpl,(bl,c)) =
554 hov 2
555 (head ++ spc() ++ pr_ident_decl idpl ++ spc() ++
556 (match bl with [] -> mt() | _ -> pr_binders bl ++ spc()) ++
557 str":" ++ pr_spc_lconstr c)
558
559 let pr_rew_rule (ubinders, lhs, rhs) =
560 let binders = match ubinders with None -> mt()
561 | _ ->
562 pr_universe_decl ubinders ++ spc() ++ str"|-"
563 in
564 let pr_pure_lconstr c = Flags.without_option Flags.beautify pr_lconstr c in
565 binders ++ pr_pure_lconstr lhs ++ str"==>" ++ pr_pure_lconstr rhs
566
567 (**************************************)
568 (* Pretty printer for vernac commands *)
569 (**************************************)
570
571 let pr_constrarg c =
572 spc () ++ pr_constr c
573 let pr_lconstrarg c =
574 spc () ++ pr_lconstr c
575 let pr_intarg n = spc () ++ int n
576
577 let pr_vernac_attributes =
578 function
579 | [] -> mt ()
580 | flags -> str "#[" ++ prlist_with_sep pr_comma Attributes.pr_vernac_flag flags ++ str "]" ++ spc ()
581
582 let pr_oc coe ins = match coe, ins with
583 | NoCoercion, NoInstance -> str" :"
584 | AddCoercion, NoInstance -> str" :>"
585 | NoCoercion, BackInstance -> str" ::"
586 | AddCoercion, BackInstance -> str" ::>"
587
588 let pr_record_field (x, { rfu_attrs = attr ; rfu_coercion = coe ; rfu_instance = ins ; rfu_priority = pri ; rfu_notation = ntn }) =
589 let prx = match x with
590 | AssumExpr (id,binders,t) ->
591 hov 1 (pr_vernac_attributes attr ++
592 pr_lname id ++
593 pr_binders_arg binders ++ spc() ++
594 pr_oc coe ins ++ spc() ++
595 pr_lconstr_expr t)
596 | DefExpr(id,binders,b,opt) -> (match opt with
597 | Some t ->
598 hov 1 (pr_vernac_attributes attr ++
599 pr_lname id ++
600 pr_binders_arg binders ++ spc() ++
601 pr_oc coe ins ++ spc() ++
602 pr_lconstr_expr t ++ str" :=" ++ pr_lconstr b)
603 | None ->
604 hov 1 (pr_vernac_attributes attr ++
605 pr_lname id ++ str" :=" ++ spc() ++
606 pr_lconstr b)) in
607 let prpri = match pri with None -> mt() | Some i -> str "| " ++ int i in
608 prx ++ prpri ++ prlist pr_where_notation ntn
609
610 let pr_record_decl c fs obinder =
611 pr_opt pr_lident c ++ pr_record "{" "}" pr_record_field fs ++
612 pr_opt (fun id -> str "as " ++ pr_lident id) obinder
613
614 let pr_printable = function
615 | PrintFullContext ->
616 keyword "Print All"
617 | PrintSectionContext s ->
618 keyword "Print Section" ++ spc() ++ Libnames.pr_qualid s
619 | PrintGrammar ent ->
620 keyword "Print Grammar" ++ spc() ++
621 prlist_with_sep spc str ent
622 | PrintCustomGrammar ent ->
623 keyword "Print Custom Grammar" ++ spc() ++ pr_qualid ent
624 | PrintKeywords ->
625 keyword "Print Keywords"
626 | PrintLoadPath dir ->
627 keyword "Print LoadPath" ++ pr_opt DirPath.print dir
628 | PrintLibraries ->
629 keyword "Print Libraries"
630 | PrintMLLoadPath ->
631 keyword "Print ML Path"
632 | PrintMLModules ->
633 keyword "Print ML Modules"
634 | PrintDebugGC ->
635 keyword "Print ML GC"
636 | PrintGraph ->
637 keyword "Print Graph"
638 | PrintClasses ->
639 keyword "Print Classes"
640 | PrintTypeclasses ->
641 keyword "Print Typeclasses"
642 | PrintInstances qid ->
643 keyword "Print Instances" ++ spc () ++ pr_smart_global qid
644 | PrintCoercions ->
645 keyword "Print Coercions"
646 | PrintCoercionPaths (s,t) ->
647 keyword "Print Coercion Paths" ++ spc()
648 ++ pr_class_rawexpr s ++ spc()
649 ++ pr_class_rawexpr t
650 | PrintCanonicalConversions qids ->
651 keyword "Print Canonical Structures" ++ prlist pr_smart_global qids
652 | PrintTypingFlags ->
653 keyword "Print Typing Flags"
654 | PrintTables ->
655 keyword "Print Tables"
656 | PrintHintGoal ->
657 keyword "Print Hint"
658 | PrintHint qid ->
659 keyword "Print Hint" ++ spc () ++ pr_smart_global qid
660 | PrintHintDb ->
661 keyword "Print Hint *"
662 | PrintHintDbName s ->
663 keyword "Print HintDb" ++ spc () ++ str s
664 | PrintUniverses {sort=b; subgraph=g; with_sources; file=fopt;} ->
665 let cmd =
666 if b then "Print Sorted Universes"
667 else "Print Universes"
668 in
669 let pr_debug_univ_name = function
670 | NamedUniv x -> pr_qualid x
671 | RawUniv { CAst.v = x } -> qstring x
672 in
673 let pr_subgraph = prlist_with_sep spc pr_debug_univ_name in
674 let pr_with_src b = if b then str "With Constraint Sources"
675 else str "Without Constraint Sources"
676 in
677 keyword cmd ++ pr_opt pr_subgraph g ++ pr_opt pr_with_src with_sources ++ pr_opt str fopt
678 | PrintSorts ->
679 keyword "Print Sorts"
680 | PrintName (qid,udecl) ->
681 keyword "Print" ++ spc() ++ pr_smart_global qid ++ pr_full_univ_name_list udecl
682 | PrintModuleType qid ->
683 keyword "Print Module Type" ++ spc() ++ pr_qualid qid
684 | PrintModule qid ->
685 keyword "Print Module" ++ spc() ++ pr_qualid qid
686 | PrintInspect n ->
687 keyword "Inspect" ++ spc() ++ int n
688 | PrintScopes ->
689 keyword "Print Scopes"
690 | PrintScope s ->
691 keyword "Print Scope" ++ spc() ++ str s
692 | PrintVisibility s ->
693 keyword "Print Visibility" ++ pr_opt str s
694 | PrintAbout (qid,l,gopt) ->
695 pr_opt (fun g -> Goal_select.pr_goal_selector g ++ str ":"++ spc()) gopt
696 ++ keyword "About" ++ spc() ++ pr_smart_global qid ++ pr_full_univ_name_list l
697 | PrintImplicit qid ->
698 keyword "Print Implicit" ++ spc() ++ pr_smart_global qid
699 (* spiwack: command printing all the axioms and section variables used in a
700 term *)
701 | PrintAssumptions (b, t, qids) ->
702 let cmd = match b, t with
703 | true, true -> "Print All Dependencies"
704 | true, false -> "Print Opaque Dependencies"
705 | false, true -> "Print Transparent Dependencies"
706 | false, false -> "Print Assumptions"
707 in
708 keyword cmd ++ spc() ++ prlist_with_sep spc pr_smart_global qids
709 | PrintNamespace dp ->
710 keyword "Print Namespace" ++ DirPath.print dp
711 | PrintStrategy None ->
712 keyword "Print Strategies"
713 | PrintStrategy (Some qid) ->
714 keyword "Print Strategy" ++ pr_smart_global qid
715 | PrintRegistered ->
716 keyword "Print Registered"
717 | PrintRegisteredSchemes ->
718 keyword "Print Registered Schemes"
719 | PrintNotation (Constrexpr.InConstrEntry, ntn_key) ->
720 keyword "Print Notation" ++ spc() ++ str ntn_key
721 | PrintNotation (Constrexpr.InCustomEntry ent, ntn_key) ->
722 keyword "Print Notation" ++ spc() ++ pr_qualid ent ++ str ntn_key
723
724 let pr_using e =
725 let rec aux = function
726 | SsEmpty -> "()"
727 | SsType -> "(Type)"
728 | SsSingl { v=id } -> "("^Id.to_string id^")"
729 | SsCompl e -> "-" ^ aux e^""
730 | SsUnion(e1,e2) -> "("^aux e1 ^" + "^ aux e2^")"
731 | SsSubstr(e1,e2) -> "("^aux e1 ^" - "^ aux e2^")"
732 | SsFwdClose e -> "("^aux e^")*"
733 in Pp.str (aux e)
734
735 let pr_extend s cl =
736 let pr_arg a =
737 try pr_gen a
738 with Failure _ -> str "<error in " ++ str s.ext_entry ++ str ">" in
739 try
740 let rl = Egramml.get_extend_vernac_rule s in
741 let rec aux rl cl =
742 match rl, cl with
743 | Egramml.GramNonTerminal _ :: rl, arg :: cl -> pr_arg arg :: aux rl cl
744 | Egramml.GramTerminal s :: rl, cl -> str s :: aux rl cl
745 | [], [] -> []
746 | _ -> assert false in
747 hov 1 (pr_sequence identity (aux rl cl))
748 with Not_found ->
749 hov 1 (str "TODO(" ++ str s.ext_entry ++ spc () ++ prlist_with_sep sep pr_arg cl ++ str ")")
750
751 let pr_synpure_vernac_expr v =
752 let return = tag_vernac v in
753 match v with
754
755 (* Proof management *)
756 | VernacAbortAll ->
757 return (keyword "Abort All")
758 | VernacRestart ->
759 return (keyword "Restart")
760 | VernacUnfocus ->
761 return (keyword "Unfocus")
762 | VernacUnfocused ->
763 return (keyword "Unfocused")
764 | VernacAbort ->
765 return (keyword "Abort")
766 | VernacUndo i ->
767 return (
768 if Int.equal i 1 then keyword "Undo" else keyword "Undo" ++ pr_intarg i
769 )
770 | VernacUndoTo i ->
771 return (keyword "Undo" ++ spc() ++ keyword "To" ++ pr_intarg i)
772 | VernacFocus i ->
773 return (keyword "Focus" ++ pr_opt int i)
774 | VernacShow s ->
775 let pr_goal_reference = function
776 | OpenSubgoals -> mt ()
777 | NthGoal n -> spc () ++ int n
778 | GoalId id -> spc () ++ pr_qualid id
779 in
780 let pr_showable = function
781 | ShowGoal n -> keyword "Show" ++ pr_goal_reference n
782 | ShowProof -> keyword "Show Proof"
783 | ShowExistentials -> keyword "Show Existentials"
784 | ShowUniverses -> keyword "Show Universes"
785 | ShowProofNames -> keyword "Show Conjectures"
786 | ShowIntros b -> keyword "Show " ++ (if b then keyword "Intros" else keyword "Intro")
787 | ShowMatch id -> keyword "Show Match " ++ pr_qualid id
788 in
789 return (pr_showable s)
790 | VernacCheckGuard ->
791 return (keyword "Guarded")
792
793 | VernacValidateProof -> return (keyword "Validate Proof")
794
795 (* Resetting *)
796 | VernacResetName id ->
797 return (keyword "Reset" ++ spc() ++ pr_lident id)
798 | VernacResetInitial ->
799 return (keyword "Reset Initial")
800 | VernacBack i ->
801 return (
802 if Int.equal i 1 then keyword "Back" else keyword "Back" ++ pr_intarg i
803 )
804
805 (* Syntax *)
806 | VernacOpenCloseScope (opening,sc) ->
807 return (
808 keyword (if opening then "Open " else "Close ") ++
809 keyword "Scope" ++ spc() ++ str sc
810 )
811 | VernacDeclareScope sc ->
812 return (
813 keyword "Declare Scope" ++ spc () ++ str sc
814 )
815 | VernacDelimiters (sc,Some key) ->
816 return (
817 keyword "Delimit Scope" ++ spc () ++ str sc ++
818 spc() ++ keyword "with" ++ spc () ++ str key
819 )
820 | VernacDelimiters (sc, None) ->
821 return (
822 keyword "Undelimit Scope" ++ spc () ++ str sc
823 )
824 | VernacBindScope (sc,cll) ->
825 return (
826 keyword "Bind Scope" ++ spc () ++ str sc ++
827 spc() ++ keyword "with" ++ spc () ++ prlist_with_sep spc pr_class_rawexpr cll
828 )
829 | VernacEnableNotation (on,rule,interp,flags,scope) ->
830 let pr_flag = function
831 | EnableNotationEntry InConstrEntry -> str "in constr"
832 | EnableNotationEntry InCustomEntry s -> str "in custom " ++ pr_qualid s
833 | EnableNotationOnly OnlyParsing -> str "only parsing"
834 | EnableNotationOnly OnlyPrinting -> str "only printing"
835 | EnableNotationOnly ParsingAndPrinting -> assert false
836 | EnableNotationAll -> str "all" in
837 let pr_flags = function
838 | [] -> mt ()
839 | l -> str "(" ++ prlist_with_sep pr_comma pr_flag l ++ str ")" in
840 let pr_rule = match rule with
841 | None -> mt ()
842 | Some (Inl ntn) -> quote (str ntn)
843 | Some (Inr abbrev) -> pr_abbreviation pr_qualid abbrev in
844 let pr_opt_scope = function
845 | None -> mt ()
846 | Some (NotationInScope s) -> spc () ++ str ": " ++ str s
847 | Some LastLonelyNotation -> str ":" ++ spc () ++ str "none" in
848 let pp = pr_rule ++ pr_flags flags ++ pr_opt_scope scope in
849 return (
850 keyword (if on then "Enable Notation " else "Disable Notation ") ++ pp
851 )
852
853 (* Gallina *)
854 | VernacDefinition ((discharge,kind),id,b) -> (* A verifier... *)
855 let isgoal = Name.is_anonymous (fst id).v in
856 let pr_def_token =
857 keyword (
858 if isgoal
859 then "Goal"
860 else string_of_definition_object_kind kind)
861 in
862 let pr_reduce = function
863 | None -> mt()
864 | Some r ->
865 keyword "Eval" ++ spc() ++
866 pr_red_expr r ++
867 keyword " in" ++ spc()
868 in
869 let pr_def_body = match b with
870 | DefineBody (bl,red,body,d) ->
871 let ty = match d with
872 | None -> mt()
873 | Some ty -> spc() ++ str":" ++ pr_spc_lconstr ty
874 in
875 pr_binders_arg bl ++ ty ++ str " :=" ++ spc() ++ pr_reduce red ++ pr_lconstr body
876 | ProveBody (bl,t) ->
877 let typ u = if isgoal then (assert (bl = []); u) else (str" :" ++ u) in
878 pr_binders_arg bl ++ typ (pr_spc_lconstr t)
879 in
880 return (
881 hov 2 (
882 pr_def_token
883 ++ (if isgoal then mt() else spc() ++ pr_lname_decl id)
884 ++ pr_def_body)
885 )
886
887 | VernacStartTheoremProof (ki,l) ->
888 return (
889 hov 1 (pr_statement (pr_thm_token ki) (List.hd l) ++
890 prlist (pr_statement (spc () ++ keyword "with")) (List.tl l))
891 )
892
893 | VernacEndProof Admitted ->
894 return (keyword "Admitted")
895
896 | VernacEndProof (Proved (opac,o)) -> return (
897 match o with
898 | None -> (match opac with
899 | Transparent -> keyword "Defined"
900 | Opaque -> keyword "Qed")
901 | Some id -> (if opac <> Transparent then keyword "Save" else keyword "Defined") ++ spc() ++ pr_lident id
902 )
903 | VernacExactProof c ->
904 return (hov 2 (keyword "Proof" ++ pr_lconstrarg c))
905 | VernacAssumption ((discharge,kind),t,l) ->
906 let n = List.length (List.flatten (List.map fst (List.map snd l))) in
907 let pr_params (c, (xl, t)) =
908 hov 2 (prlist_with_sep sep pr_ident_decl xl ++ spc() ++
909 str(match c with AddCoercion -> ":>" | NoCoercion -> ":") ++ spc() ++ pr_lconstr_expr t) in
910 let assumptions = prlist_with_sep spc (fun p -> hov 1 (str "(" ++ pr_params p ++ str ")")) l in
911 return (hov 2 (pr_assumption_token (n > 1) discharge kind ++
912 pr_non_empty_arg pr_assumption_inline t ++ spc() ++ assumptions))
913 | VernacSymbol l ->
914 let n = List.length (List.flatten (List.map fst (List.map snd l))) in
915 let pr_params (c, (xl, t)) =
916 hov 2 (prlist_with_sep sep pr_ident_decl xl ++ spc() ++
917 str(match c with AddCoercion -> ":>" | NoCoercion -> ":") ++ spc() ++ pr_lconstr_expr t) in
918 let assumptions = prlist_with_sep spc (fun p -> hov 1 (str "(" ++ pr_params p ++ str ")")) l in
919 return (hov 2 (keyword (if (n > 1) then "Symbols" else "Symbol") ++ spc() ++ assumptions))
920 | VernacInductive (f,l) ->
921 let pr_constructor ((attr,coe,ins),(id,c)) =
922 hov 2 (pr_vernac_attributes attr ++ pr_lident id ++ pr_oc coe ins ++
923 Flags.without_option Flags.beautify pr_spc_lconstr c)
924 in
925 let pr_constructor_list l = match l with
926 | Constructors [] -> mt()
927 | Constructors l ->
928 let fst_sep = match l with [_] -> " " | _ -> " | " in
929 pr_com_at (begin_of_inductive l) ++
930 fnl() ++ str fst_sep ++
931 prlist_with_sep (fun _ -> fnl() ++ str" | ") pr_constructor l
932 | RecordDecl (c,fs,obinder) ->
933 pr_record_decl c fs obinder
934 in
935 let pr_oneind key (((coe,iddecl),(indupar,indpar),s,lc),ntn) =
936 hov 0 (
937 str key ++ spc() ++
938 str(match coe with AddCoercion -> "> " | NoCoercion -> "") ++ pr_cumul_ident_decl iddecl ++
939 pr_and_type_binders_arg indupar ++
940 pr_opt (fun p -> str "|" ++ spc() ++ pr_and_type_binders_arg p) indpar ++
941 pr_opt (fun s -> str":" ++ spc() ++ pr_lconstr_expr s) s ++
942 str" :=") ++ pr_constructor_list lc ++
943 prlist pr_where_notation ntn
944 in
945 let kind =
946 match f with
947 | Record -> "Record" | Structure -> "Structure"
948 | Inductive_kw -> "Inductive" | CoInductive -> "CoInductive"
949 | Class _ -> "Class" | Variant -> "Variant"
950 in
951 return (
952 hov 1 (pr_oneind kind (List.hd l)) ++
953 (prlist (fun ind -> fnl() ++ hov 1 (pr_oneind "with" ind)) (List.tl l))
954 )
955
956 | VernacFixpoint (local, (rec_order, recs)) ->
957 let local = match local with
958 | DoDischarge -> "Let "
959 | NoDischarge -> ""
960 in
961 return (
962 hov 0 (str local ++ keyword "Fixpoint" ++ spc () ++
963 prlist_with_sep (fun _ -> fnl () ++ keyword "with"
964 ++ spc ()) pr_rec_definition (List.combine rec_order recs))
965 )
966
967 | VernacCoFixpoint (local, corecs) ->
968 let local = match local with
969 | DoDischarge -> keyword "Let" ++ spc ()
970 | NoDischarge -> str ""
971 in
972 let pr_onecorec {fname; univs; binders; rtype; body_def; notations } =
973 pr_ident_decl (fname,univs) ++ spc() ++ pr_binders binders ++ spc() ++ str":" ++
974 spc() ++ pr_lconstr_expr rtype ++
975 pr_opt (fun def -> str":=" ++ brk(1,2) ++ pr_lconstr def) body_def ++
976 prlist pr_where_notation notations
977 in
978 return (
979 hov 0 (local ++ keyword "CoFixpoint" ++ spc() ++
980 prlist_with_sep (fun _ -> fnl() ++ keyword "with" ++ spc ()) pr_onecorec corecs)
981 )
982 | VernacSchemeAll (id, lid) ->
983 return (
984 hov 2 (keyword "Scheme " ++ keyword "All" ++ str " for" ++ spc() ++ pr_smart_global id
985 ++ pr_opt (fun x -> str " over" ++ spc() ++ prlist_with_sep pr_comma Id.print x) lid)
986 )
987 | VernacScheme l ->
988 return (
989 hov 2 (keyword "Scheme" ++ spc() ++
990 prlist_with_sep (fun _ -> fnl() ++ keyword "with" ++ spc ()) pr_onescheme l)
991 )
992 | VernacSchemeEquality (sch,id) ->
993 return (
994 hov 2 (keyword "Scheme " ++ pr_equality_scheme_type sch id)
995 )
996 | VernacCombinedScheme (id, l) ->
997 return (
998 hov 2 (keyword "Combined Scheme" ++ spc() ++
999 pr_lident id ++ spc() ++ keyword "from" ++ spc() ++
1000 prlist_with_sep (fun _ -> fnl() ++ str", ") pr_lident l)
1001 )
1002 | VernacUniverse v ->
1003 return (
1004 hov 2 (keyword "Universe" ++ spc () ++
1005 prlist_with_sep (fun _ -> str",") pr_lident v)
1006 )
1007 | VernacSort v ->
1008 return (
1009 hov 2 (keyword "Sort" ++ spc () ++
1010 prlist_with_sep (fun _ -> str",") pr_lident v)
1011 )
1012 | VernacConstraint v ->
1013 return (
1014 hov 2 (keyword "Constraint" ++ spc () ++
1015 prlist_with_sep (fun _ -> str",") pr_pconstraint v)
1016 )
1017
1018 (* Gallina extensions *)
1019 | VernacNameSectionHypSet (id,set) ->
1020 return (hov 2 (keyword "Collection" ++ spc() ++ pr_lident id ++ spc()++
1021 str ":="++spc()++pr_using set))
1022 | VernacCanonical q ->
1023 return (
1024 keyword "Canonical Structure" ++ spc() ++ pr_smart_global q
1025 )
1026 | VernacCoercion (id,Some(c1,c2)) ->
1027 return (
1028 hov 1 (
1029 keyword "Coercion" ++ spc() ++
1030 pr_smart_global id ++ spc() ++ str":" ++ spc() ++ pr_class_rawexpr c1 ++
1031 spc() ++ str">->" ++ spc() ++ pr_class_rawexpr c2)
1032 )
1033 | VernacCoercion (id,None) ->
1034 return (
1035 hov 1 (
1036 keyword "Coercion" ++ spc() ++
1037 pr_smart_global id)
1038 )
1039 | VernacIdentityCoercion (id,c1,c2) ->
1040 return (
1041 hov 1 (
1042 keyword "Identity Coercion" ++ spc() ++ pr_lident id ++
1043 spc() ++ str":" ++ spc() ++ pr_class_rawexpr c1 ++ spc() ++ str">->" ++
1044 spc() ++ pr_class_rawexpr c2)
1045 )
1046
1047 | VernacInstance (instid, sup, cl, props, info) ->
1048 return (
1049 hov 1 (
1050 keyword "Instance" ++
1051 (match instid with
1052 | {loc; v = Name id}, l -> spc () ++ pr_ident_decl (CAst.(make ?loc id),l) ++ spc ()
1053 | { v = Anonymous }, _ -> mt ()) ++
1054 pr_and_type_binders_arg sup ++
1055 str":" ++ spc () ++
1056 pr_constr cl ++ pr_hint_info pr_constr_pattern_expr info ++
1057 (match props with
1058 | Some (true, { v = CRecord l}) -> spc () ++ str":=" ++ spc () ++ pr_record_body "{" "}" pr_lconstr l
1059 | Some (true,_) -> assert false
1060 | Some (false,p) -> spc () ++ str":=" ++ spc () ++ pr_constr p
1061 | None -> mt()))
1062 )
1063
1064 | VernacDeclareInstance (instid, sup, cl, info) ->
1065 return (
1066 hov 1 (
1067 keyword "Declare Instance" ++ spc () ++ pr_ident_decl instid ++ spc () ++
1068 pr_and_type_binders_arg sup ++
1069 str":" ++ spc () ++
1070 pr_constr cl ++ pr_hint_info pr_constr_pattern_expr info)
1071 )
1072
1073 | VernacContext l ->
1074 return (
1075 hov 1 (
1076 keyword "Context" ++ pr_and_type_binders_arg l)
1077 )
1078
1079 | VernacExistingInstance insts ->
1080 let pr_inst (id, info) =
1081 pr_qualid id ++ pr_hint_info pr_constr_pattern_expr info
1082 in
1083 return (
1084 hov 1 (keyword "Existing" ++ spc () ++
1085 keyword(String.plural (List.length insts) "Instance") ++
1086 spc () ++ prlist_with_sep spc pr_inst insts)
1087 )
1088
1089 | VernacExistingClass id ->
1090 return (
1091 hov 1 (keyword "Existing" ++ spc () ++ keyword "Class" ++ spc () ++ pr_qualid id)
1092 )
1093
1094 (* Commands *)
1095 | VernacCreateHintDb (dbname,b) ->
1096 return (
1097 hov 1 (keyword "Create HintDb" ++ spc () ++
1098 str dbname ++ (if b then str" discriminated" else mt ()))
1099 )
1100 | VernacRemoveHints (dbnames, ids) ->
1101 return (
1102 hov 1 (keyword "Remove Hints" ++ spc () ++
1103 prlist_with_sep spc (fun r -> pr_qualid r) ids ++
1104 pr_opt_hintbases dbnames)
1105 )
1106 | VernacHints (dbnames,h) ->
1107 return (pr_hints dbnames h pr_constr pr_constr_pattern_expr)
1108 | VernacAbbreviation (id,(ids,c),l,_) ->
1109 return (
1110 hov 2
1111 (keyword "Abbreviation" ++ spc () ++ pr_abbreviation pr_lident (ids,id) ++ str":=" ++ pr_constrarg c ++
1112 pr_syntax_modifiers l)
1113 )
1114 | VernacArguments (q, args, more_implicits, mods) ->
1115 return (
1116 hov 2 (
1117 keyword "Arguments" ++ spc() ++
1118 pr_smart_global q ++
1119 let pr_s = prlist (fun {v=s} -> pr_scope_delimiter s) in
1120 let pr_if b x = if b then x else str "" in
1121 let pr_one_arg (x,k) = pr_if k (str"!") ++ Name.print x in
1122 let pr_br imp force x =
1123 let left,right =
1124 match imp with
1125 | Glob_term.NonMaxImplicit -> str "[", str "]"
1126 | Glob_term.MaxImplicit -> str "{", str "}"
1127 | Glob_term.Explicit -> if force then str"(",str")" else mt(),mt()
1128 in
1129 left ++ x ++ right
1130 in
1131 let get_arguments_like s imp tl =
1132 if s = [] && imp = Glob_term.Explicit then [], tl
1133 else
1134 let rec fold extra = function
1135 | RealArg arg :: tl when
1136 List.equal
1137 (fun a b -> let da, a = a.CAst.v in let db, b = b.CAst.v in
1138 da = db && String.equal a b) arg.notation_scope s
1139 && arg.implicit_status = imp ->
1140 fold ((arg.name,arg.recarg_like) :: extra) tl
1141 | args -> List.rev extra, args
1142 in
1143 fold [] tl
1144 in
1145 let rec print_arguments = function
1146 | [] -> mt()
1147 | VolatileArg :: l -> spc () ++ str"/" ++ print_arguments l
1148 | BidiArg :: l -> spc () ++ str"&" ++ print_arguments l
1149 | RealArg { name = id; recarg_like = k;
1150 notation_scope = s;
1151 implicit_status = imp } :: tl ->
1152 let extra, tl = get_arguments_like s imp tl in
1153 spc() ++ hov 1 (pr_br imp (extra<>[]) (prlist_with_sep spc pr_one_arg ((id,k)::extra)) ++
1154 pr_s s) ++ print_arguments tl
1155 in
1156 let rec print_implicits = function
1157 | [] -> mt ()
1158 | (name, impl) :: rest ->
1159 spc() ++ pr_br impl false (Name.print name) ++ print_implicits rest
1160 in
1161 print_arguments args ++
1162 if not (List.is_empty more_implicits) then
1163 prlist (fun l -> str"," ++ print_implicits l) more_implicits
1164 else (mt ()) ++
1165 (if not (List.is_empty mods) then str" : " else str"") ++
1166 prlist_with_sep (fun () -> str", " ++ spc()) (function
1167 | `SimplDontExposeCase -> keyword "simpl nomatch"
1168 | `SimplNeverUnfold -> keyword "simpl never"
1169 | `DefaultImplicits -> keyword "default implicits"
1170 | `Rename -> keyword "rename"
1171 | `Assert -> keyword "assert"
1172 | `ExtraScopes -> keyword "extra scopes"
1173 | `ClearImplicits -> keyword "clear implicits"
1174 | `ClearReduction -> keyword "clear simpl"
1175 | `ClearScopes -> keyword "clear scopes"
1176 | `ClearBidiHint -> keyword "clear bidirectionality hint")
1177 mods)
1178 )
1179 | VernacReserve bl ->
1180 let n = List.length (List.flatten (List.map fst bl)) in
1181 return (
1182 hov 2 (tag_keyword (str"Implicit Type" ++ str (if n > 1 then "s " else " "))
1183 ++ pr_ne_params_list pr_lconstr_expr (List.map (fun sb -> false,sb) bl))
1184 )
1185 | VernacGeneralizable g ->
1186 return (
1187 hov 1 (tag_keyword (
1188 str"Generalizable Variable" ++
1189 match g with
1190 | None -> str "s none"
1191 | Some [] -> str "s all"
1192 | Some idl ->
1193 str (if List.length idl > 1 then "s " else " ") ++
1194 prlist_with_sep spc pr_lident idl)
1195 ))
1196 | VernacSetOpacity((k,l),b) when Conv_oracle.is_transparent k ->
1197 return (
1198 hov 1 (keyword (if b then "Transparent!" else "Transparent") ++
1199 spc() ++ prlist_with_sep sep pr_smart_global l)
1200 )
1201 | VernacSetOpacity((Conv_oracle.Opaque,l),b) ->
1202 return (
1203 hov 1 (keyword (if b then "Opaque!" else "Opaque") ++
1204 spc() ++ prlist_with_sep sep pr_smart_global l)
1205 )
1206 | VernacSetOpacity _ ->
1207 return (
1208 CErrors.anomaly (keyword "VernacSetOpacity used to set something else.")
1209 )
1210 | VernacSetStrategy l ->
1211 let pr_lev = function
1212 | Conv_oracle.Opaque -> keyword "opaque"
1213 | Conv_oracle.Expand -> keyword "expand"
1214 | l when Conv_oracle.is_transparent l -> keyword "transparent"
1215 | Conv_oracle.Level n -> int n
1216 in
1217 let pr_line (l,q) =
1218 hov 2 (pr_lev l ++ spc() ++
1219 str"[" ++ prlist_with_sep sep pr_smart_global q ++ str"]")
1220 in
1221 return (
1222 hov 1 (keyword "Strategy" ++ spc() ++
1223 hv 0 (prlist_with_sep sep pr_line l))
1224 )
1225 | VernacAddOption (na,l) ->
1226 return (
1227 hov 2 (keyword "Add" ++ spc() ++ pr_printoption na (Some l))
1228 )
1229 | VernacRemoveOption (na,l) ->
1230 return (
1231 hov 2 (keyword "Remove" ++ spc() ++ pr_printoption na (Some l))
1232 )
1233 | VernacMemOption (na,l) ->
1234 return (
1235 hov 2 (keyword "Test" ++ spc() ++ pr_printoption na (Some l))
1236 )
1237 | VernacPrintOption na ->
1238 return (
1239 hov 2 (keyword "Test" ++ spc() ++ pr_printoption na None)
1240 )
1241 | VernacCheckMayEval (r,io,c) ->
1242 let pr_mayeval r c = match r with
1243 | Some r0 ->
1244 hov 2 (keyword "Eval" ++ spc() ++
1245 pr_red_expr r0 ++
1246 spc() ++ keyword "in" ++ spc () ++ pr_lconstr c)
1247 | None -> hov 2 (keyword "Check" ++ spc() ++ pr_lconstr c)
1248 in
1249 let pr_i = match io with None -> mt ()
1250 | Some i -> Goal_select.pr_goal_selector i ++ str ": " in
1251 return (pr_i ++ pr_mayeval r c)
1252 | VernacGlobalCheck c ->
1253 return (hov 2 (keyword "Type" ++ pr_constrarg c))
1254 | VernacDeclareReduction (s,r) ->
1255 return (
1256 keyword "Declare Reduction" ++ spc () ++ str s ++ str " := " ++
1257 pr_red_expr r
1258 )
1259 | VernacPrint p ->
1260 return (pr_printable p)
1261 | VernacSearch (sea,g,sea_r) ->
1262 return (pr_search sea g sea_r @@ pr_constr_pattern_expr)
1263 | VernacLocate loc ->
1264 let pr_locate =function
1265 | LocateAny qid -> pr_smart_global qid
1266 | LocateTerm qid -> keyword "Term" ++ spc() ++ pr_smart_global qid
1267 | LocateFile f -> keyword "File" ++ spc() ++ qs f
1268 | LocateLibrary qid -> keyword "Library" ++ spc () ++ pr_module qid
1269 | LocateModule qid -> keyword "Module" ++ spc () ++ pr_module qid
1270 | LocateOther (s, qid) -> keyword s ++ spc () ++ pr_ltac_ref qid
1271 in
1272 return (keyword "Locate" ++ spc() ++ pr_locate loc)
1273 | VernacRegister (qid, RegisterCoqlib name) ->
1274 return (
1275 hov 2
1276 (keyword "Register" ++ spc() ++ pr_qualid qid ++ spc () ++ str "as"
1277 ++ spc () ++ pr_qualid name)
1278 )
1279 | VernacRegister (qid, RegisterScheme {inductive; scheme_kind}) ->
1280 return (
1281 hov 2
1282 (keyword "Register" ++ spc() ++ keyword "Scheme" ++ spc() ++ pr_qualid qid ++ spc () ++ str "as"
1283 ++ spc () ++ pr_qualid scheme_kind ++ spc() ++ str "for" ++ spc() ++ pr_qualid inductive)
1284 )
1285 | VernacRegister (qid, RegisterInline) ->
1286 return (
1287 hov 2
1288 (keyword "Register Inline" ++ spc() ++ pr_qualid qid)
1289 )
1290 | VernacPrimitive(id,r,typopt) ->
1291 hov 2
1292 (keyword "Primitive" ++ spc() ++ pr_ident_decl id ++
1293 (Option.cata (fun ty -> spc() ++ str":" ++ pr_spc_lconstr ty) (mt()) typopt) ++ spc() ++
1294 str ":=" ++ spc() ++
1295 str (CPrimitives.op_or_type_to_string r))
1296 | VernacComments l ->
1297 return (
1298 hov 2
1299 (keyword "Comments" ++ spc()
1300 ++ prlist_with_sep sep (pr_comment pr_constr) l)
1301 )
1302 | VernacAttributes attrs ->
1303 return (
1304 hov 2
1305 (keyword "Attributes" ++ spc () ++
1306 pr_vernac_attributes attrs)
1307 )
1308 | VernacProof (None, None) ->
1309 return (keyword "Proof")
1310 | VernacProof (None, Some e) ->
1311 return (keyword "Proof " ++ spc () ++
1312 keyword "using" ++ spc() ++ pr_using e)
1313 | VernacProof (Some te, None) ->
1314 return (keyword "Proof with" ++ spc() ++ pr_gentac te)
1315 | VernacProof (Some te, Some e) ->
1316 return (
1317 keyword "Proof" ++ spc () ++
1318 keyword "using" ++ spc() ++ pr_using e ++ spc() ++
1319 keyword "with" ++ spc() ++ pr_gentac te
1320 )
1321 | VernacBullet b ->
1322 (* XXX: Redundant with Proof_bullet.print *)
1323 return (let open Proof_bullet in begin match b with
1324 | Dash n -> str (String.make n '-')
1325 | Star n -> str (String.make n '*')
1326 | Plus n -> str (String.make n '+')
1327 end)
1328 | VernacSubproof None ->
1329 return (str "{")
1330 | VernacSubproof (Some i) ->
1331 return (Goal_select.pr_goal_selector i ++ str ":" ++ spc () ++ str "{")
1332 | VernacEndSubproof ->
1333 return (str "}")
1334
1335 | VernacAddRewRule (id, l) ->
1336 return (
1337 hov 0 (keyword (if List.length l > 1 then "Rewrite Rules" else "Rewrite Rule") ++ spc () ++
1338 pr_lident id ++ str ":=" ++
1339 prlist_with_sep (fun _ -> fnl () ++ keyword "with"
1340 ++ spc ()) pr_rew_rule l)
1341 )
1342
1343 let pr_synterp_vernac_expr v =
1344 let return = tag_vernac v in
1345 match v with
1346 | VernacLoad (f,s) ->
1347 return (
1348 keyword "Load"
1349 ++ if f then
1350 (spc() ++ keyword "Verbose" ++ spc())
1351 else
1352 spc() ++ qs s
1353 )
1354
1355 | VernacBeginSection id ->
1356 return (hov 2 (keyword "Section" ++ spc () ++ pr_lident id))
1357 | VernacEndSegment id ->
1358 return (hov 2 (keyword "End" ++ spc() ++ pr_lident id))
1359 | VernacNotation (infix,ntn_decl) ->
1360 return (
1361 hov 2 (hov 0 (keyword (if infix then "Infix" else "Notation") ++ spc() ++
1362 pr_notation_declaration ntn_decl))
1363 )
1364 | VernacReservedNotation (_, (s, l)) ->
1365 return (
1366 keyword "Reserved Notation" ++ spc() ++ pr_ast qs s ++
1367 pr_syntax_modifiers l
1368 )
1369 | VernacDeclareCustomEntry s ->
1370 return (
1371 keyword "Declare Custom Entry " ++ Id.print s
1372 )
1373 | VernacRequire (from, exp, l) ->
1374 let from = match from with
1375 | None -> mt ()
1376 | Some r -> keyword "From" ++ spc () ++ pr_module r ++ spc ()
1377 in
1378 return (
1379 hov 2
1380 (from ++ keyword "Require" ++ spc() ++ pr_require_token exp ++
1381 prlist_with_sep sep pr_import_module l)
1382 )
1383 | VernacImport (f,l) ->
1384 return (
1385 pr_export_with_cats f ++ spc() ++
1386 prlist_with_sep sep pr_import_module l
1387 )
1388 (* Modules and Module Types *)
1389 | VernacDefineModule (export,m,bl,tys,bd) ->
1390 let b = pr_module_binders bl pr_lconstr in
1391 return (
1392 hov 2 (keyword "Module" ++ spc() ++ pr_require_token export ++
1393 pr_lident m ++ b ++
1394 pr_of_module_type pr_lconstr tys ++
1395 (if List.is_empty bd then mt () else str ":= ") ++
1396 prlist_with_sep (fun () -> str " <+")
1397 (pr_module_ast_inl true pr_lconstr) bd)
1398 )
1399 | VernacDeclareModule (export,id,bl,m1) ->
1400 let b = pr_module_binders bl pr_lconstr in
1401 return (
1402 hov 2 (keyword "Declare Module" ++ spc() ++ pr_require_token export ++
1403 pr_lident id ++ b ++ str " :" ++
1404 pr_module_ast_inl true pr_lconstr m1)
1405 )
1406 | VernacDeclareModuleType (id,bl,tyl,m) ->
1407 let b = pr_module_binders bl pr_lconstr in
1408 let pr_mt = pr_module_ast_inl true pr_lconstr in
1409 return (
1410 hov 2 (keyword "Module Type " ++ pr_lident id ++ b ++
1411 prlist_strict (fun m -> str " <:" ++ pr_mt m) tyl ++
1412 (if List.is_empty m then mt () else str ":= ") ++
1413 prlist_with_sep (fun () -> str " <+ ") pr_mt m)
1414 )
1415 | VernacInclude (mexprs) ->
1416 let pr_m = pr_module_ast_inl false pr_lconstr in
1417 return (
1418 hov 2 (keyword "Include" ++ spc() ++
1419 prlist_with_sep (fun () -> str " <+ ") pr_m mexprs)
1420 )
1421
1422 (* Auxiliary file and library management *)
1423 | VernacDeclareMLModule (l) ->
1424 return (
1425 hov 2 (keyword "Declare ML Module" ++ spc() ++ prlist_with_sep sep qs l)
1426 )
1427 | VernacChdir None ->
1428 return (keyword "Pwd")
1429 | VernacChdir (Some s) ->
1430 return (keyword "Cd " ++ qs s)
1431 | VernacSetOption (export, na,v) ->
1432 let export = if export then keyword "Export" ++ spc () else mt () in
1433 let set = if v == OptionUnset then "Unset" else "Set" in
1434 return (
1435 hov 2 (export ++ keyword set ++ spc() ++ pr_set_option na v)
1436 )
1437 | VernacExtraDependency(from,file,id) ->
1438 return (
1439 hov 2
1440 (keyword "From" ++ spc () ++ pr_module from ++ spc () ++
1441 keyword "Extra" ++ spc() ++ keyword "Dependency" ++ spc() ++ qs file ++
1442 pr_opt (fun x -> spc() ++ keyword "as" ++ spc () ++ pr_id x) id)
1443 )
1444 | VernacExtend (s,c) ->
1445 return (pr_extend s c)
1446 | VernacProofMode s ->
1447 return (keyword "Proof Mode" ++ str s)
1448
1449 let pr_control_flag (p : control_flag) =
1450 let w = match p.v with
1451 | ControlTime -> keyword "Time"
1452 | ControlInstructions -> keyword "Instructions"
1453 | ControlProfile f -> keyword "Profile" ++ pr_opt qstring f
1454 | ControlRedirect s -> keyword "Redirect" ++ spc() ++ qs s
1455 | ControlTimeout n -> keyword "Timeout " ++ int n
1456 | ControlFail -> keyword "Fail"
1457 | ControlSucceed -> keyword "Succeed"
1458 in
1459 w ++ spc ()
1460
1461 let pr_vernac_control flags = Pp.prlist pr_control_flag flags
1462
1463 let pr_vernac_expr v =
1464 match v with
1465 | VernacSynPure e -> pr_synpure_vernac_expr e
1466 | VernacSynterp e -> pr_synterp_vernac_expr e
1467
1468 let pr_vernac ({v = {control; attrs; expr}} as v) =
1469 tag_vernac v
1470 (pr_vernac_control control ++
1471 pr_vernac_attributes attrs ++
1472 pr_vernac_expr expr ++
1473 sep_end expr)