(************************************************************************) (* * The Rocq Prover / The Rocq 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 ?level:None) let pr_gentac = pr_in_global_env (Gentactic.print_raw ?level:None)
(* 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_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 ++
(ifList.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_qualities l extensible = (* "extensible" not really supported in syntax currently *) ifList.is_empty l then mt() else prlist_with_sep spc pr_lident l ++ strbrk " ; "
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 = ifList.is_empty l && extensible then mt () else pr_spcbar () ++ prlist_with_sep pr_comma pr_uconstraint l ++
(if extensible then str"+"else mt())
let pr_universe_decl l = letopen UState in match l with
| None -> mt ()
| Some l ->
str"@{" ++
pr_univdecl_qualities l.univdecl_qualities l.univdecl_extensible_qualities ++
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 = letopen UState in match l with
| None -> mt ()
| Some l ->
str"@{" ++
pr_univdecl_qualities l.univdecl_qualities l.univdecl_extensible_qualities ++
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_definition_object_kind = letopen 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 = letopen Decls in function
| Definitional -> "Parameter"
| Logical -> "Axiom"
| Conjectural -> "Conjecture"
| Context -> "Context"
let string_of_logical_kind = letopen 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_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 = letopen 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 -> (ifOption.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 = letopen 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"
| HintsProjections -> keyword "Projections"
| 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_gentac 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_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() ++ UnivGen.QualityOrSet.pr Sorts.QVar.raw_pr 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
let pr_rec_definition (rec_order, { fname; univs; 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
(* 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)
)
let pr_synterp_vernac_expr v = let return = tag_vernac v in match v with
| VernacLoad (f,s) ->
return (
keyword "Load"
++ if f then
(spc() ++ keyword "Verbose" ++ spc()) else
spc() ++ qs s
)
| VernacBeginSection id ->
return (hov 2 (keyword "Section" ++ spc () ++ pr_lident id))
| VernacEndSegment id ->
return (hov 2 (keyword "End" ++ spc() ++ pr_lident id))
| VernacNotation (infix,ntn_decl) ->
return (
hov 2 (hov 0 (keyword (if infix then"Infix"else"Notation") ++ spc() ++
pr_notation_declaration ntn_decl))
)
| VernacReservedNotation (_, (s, l)) ->
return (
keyword "Reserved Notation" ++ spc() ++ pr_ast qs s ++
pr_syntax_modifiers l
)
| VernacDeclareCustomEntry s ->
return (
keyword "Declare Custom Entry " ++ str s
)
| VernacRequire (from, exp, l) -> let from = match from with
| None -> mt ()
| Some r -> keyword "From" ++ spc () ++ pr_module r ++ spc () in
return (
hov 2
(from ++ keyword "Require" ++ spc() ++ pr_require_token exp ++
prlist_with_sep sep pr_import_module l)
)
| VernacImport (f,l) ->
return (
pr_export_with_cats f ++ spc() ++
prlist_with_sep sep pr_import_module l
) (* Modules and Module Types *)
| VernacDefineModule (export,m,bl,tys,bd) -> let b = pr_module_binders bl pr_lconstr in
return (
hov 2 (keyword "Module" ++ spc() ++ pr_require_token export ++
pr_lident m ++ b ++
pr_of_module_type pr_lconstr tys ++
(ifList.is_empty bd then mt () else str ":= ") ++
prlist_with_sep (fun () -> str " <+")
(pr_module_ast_inl true pr_lconstr) bd)
)
| VernacDeclareModule (export,id,bl,m1) -> let b = pr_module_binders bl pr_lconstr in
return (
hov 2 (keyword "Declare Module" ++ spc() ++ pr_require_token export ++
pr_lident id ++ b ++ str " :" ++
pr_module_ast_inl true pr_lconstr m1)
)
| VernacDeclareModuleType (id,bl,tyl,m) -> let b = pr_module_binders bl pr_lconstr in let pr_mt = pr_module_ast_inl true pr_lconstr in
return (
hov 2 (keyword "Module Type " ++ pr_lident id ++ b ++
prlist_strict (fun m -> str " <:" ++ pr_mt m) tyl ++
(ifList.is_empty m then mt () else str ":= ") ++
prlist_with_sep (fun () -> str " <+ ") pr_mt m)
)
| VernacInclude (mexprs) -> let pr_m = pr_module_ast_inl false pr_lconstr in
return (
hov 2 (keyword "Include" ++ spc() ++
prlist_with_sep (fun () -> str " <+ ") pr_m mexprs)
)
let pr_control_flag (p : control_flag) = let w = match p with
| ControlTime -> keyword "Time"
| ControlInstructions -> keyword "Instructions"
| ControlProfile f -> keyword "Profile" ++ pr_opt qstring f
| ControlRedirect s -> keyword "Redirect" ++ spc() ++ qs s
| ControlTimeout n -> keyword "Timeout " ++ int n
| ControlFail -> keyword "Fail"
| ControlSucceed -> keyword "Succeed" in
w ++ spc ()
let pr_vernac_control flags = Pp.prlist pr_control_flag flags
let pr_vernac_expr v = match v with
| VernacSynPure e -> pr_synpure_vernac_expr e
| VernacSynterp e -> pr_synterp_vernac_expr e
let pr_vernac ({v = {control; attrs; expr}} as v) =
tag_vernac v
(pr_vernac_control control ++
pr_vernac_attributes attrs ++
pr_vernac_expr expr ++
sep_end expr)
¤ Dauer der Verarbeitung: 0.75 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.