2 ref (fun ~context ~subst ~metasenv ?inside_fix t -> "Please, set a pp callback")
5 let set_ppterm f = ppterm := f;;
7 let ppterm ~context ~subst ~metasenv ?inside_fix t =
8 !ppterm ~context ~subst ~metasenv ?inside_fix t
14 let r2s pp_fix_name r =
17 | R.Ref (_,u,R.Ind i) ->
18 (match snd(NCicEnvironment.get_obj u) with
19 | _,_,_,_, C.Inductive (_,_,itl,_) ->
20 let _,name,_,_ = List.nth itl i in name
22 | R.Ref (_,u,R.Con (i,j)) ->
23 (match snd(NCicEnvironment.get_obj u) with
24 | _,_,_,_, C.Inductive (_,_,itl,_) ->
25 let _,_,_,cl = List.nth itl i in
26 let _,name,_ = List.nth cl (j-1) in name
28 | R.Ref (_,u,(R.Decl | R.Def )) ->
29 (match snd(NCicEnvironment.get_obj u) with
30 | _,_,_,_, C.Constant (_,name,_,_,_) -> name
32 | R.Ref (_,u,(R.Fix (i,_)|R.CoFix i)) ->
33 (match snd(NCicEnvironment.get_obj u) with
34 | _,_,_,_, C.Fixpoint (_,fl,_) ->
36 let _,name,_,_,_ = List.nth fl i in name
38 let name = NUri.string_of_uri u in
39 let name = Filename.basename name in
40 let name = Filename.chop_extension name in
41 name ^"("^ string_of_int i ^ ")"
43 with exn -> R.string_of_reference r
46 let trivial_pp_term ~context ~subst ~metasenv ?(inside_fix=false) t =
47 let buff = Buffer.create 100 in
48 let f = Format.formatter_of_buffer buff in
49 let module F = Format in
50 let rec aux ?(toplevel=false) ctx = function
53 let name = List.nth ctx (m-1) in
54 F.fprintf f "%s" (if name = "_" then "__"^string_of_int m else name)
55 with Failure _ -> F.fprintf f " -%d" (m - List.length context))
56 | C.Const r -> F.fprintf f "%s" (r2s inside_fix r)
58 if not toplevel then F.fprintf f "(";
59 F.fprintf f "@[<hov 1>";
61 | C.Prod ("_",_,_) -> aux ~toplevel:false ctx s
62 | _ -> aux ~toplevel:true ctx s);
64 aux ~toplevel:true ("_"::ctx) t;
66 if not toplevel then F.fprintf f ")";
67 | C.Prod (name,s,t) ->
68 if not toplevel then F.fprintf f "(";
69 F.fprintf f "@[<hov 1>";
70 F.fprintf f "@[<hov 2>∀%s:@;" name;
71 aux ~toplevel:true ctx s;
73 aux ~toplevel:true (name::ctx) t;
75 if not toplevel then F.fprintf f ")";
76 | C.Lambda (name,s,t) ->
77 if not toplevel then F.fprintf f "(";
78 F.fprintf f "@[<hov 1>";
79 F.fprintf f "λ%s:" name;
80 aux ~toplevel:true ctx s;
82 aux ~toplevel:true (name::ctx) t;
84 if not toplevel then F.fprintf f ")";
85 | C.LetIn (name,ty,t,b) ->
86 if not toplevel then F.fprintf f "(";
87 F.fprintf f "@[<hov 1>";
88 F.fprintf f "let %s:@;" name;
89 aux ~toplevel:true ctx ty;
91 aux ~toplevel:true ctx t;
93 (aux ~toplevel:true (name::ctx) b);
95 if not toplevel then F.fprintf f ")";
96 | C.Match (r,oty,t,pl) ->
97 F.fprintf f "@[<hov>match ";
98 aux ~toplevel:true ctx t;
99 F.fprintf f "@;return ";
100 aux ~toplevel:true ctx oty;
101 F.fprintf f "@; @[<v>[ ";
104 F.fprintf f "@[<hov 2>%s ⇒@;" (r2s inside_fix (R.mk_constructor 1 r));
105 aux ~toplevel:true ctx (List.hd pl);
107 ignore(List.fold_left
109 F.fprintf f "@;| @[<hov 2>%s ⇒@;" (r2s inside_fix (R.mk_constructor i r));
110 aux ~toplevel:true ctx t;
115 F.fprintf f "]@] @]";
117 F.fprintf f "@[<hov 2>";
118 if not toplevel then F.fprintf f "(";
120 List.iter (fun x -> F.fprintf f "@;";aux ctx x) (List.tl l);
121 if not toplevel then F.fprintf f ")";
123 | C.Implicit _ -> F.fprintf f "?"
124 | C.Meta (n,_) -> F.fprintf f "?%d" n
125 | C.Sort C.Prop -> F.fprintf f "Prop"
126 | C.Sort C.CProp -> F.fprintf f "CProp"
127 | C.Sort (C.Type n) -> F.fprintf f "Type%d" n
129 aux ~toplevel:true (List.map fst context) t;
135 | (u,_,metasenv,subst,NCic.Fixpoint (b, fl, _)) ->
136 "{"^NUri.string_of_uri u^"}\n"^
138 String.concat "\nand "
139 (List.map (fun (_,name,n,ty,bo) ->
140 name^ " on " ^ string_of_int n ^ " : " ^
141 ppterm ~metasenv ~subst ~context:[] ty ^ " :=\n"^
142 ppterm ~metasenv ~subst ~context:[] ~inside_fix:true bo) fl)
143 | (u,_,metasenv,subst,NCic.Inductive (b, leftno,tyl, _)) ->
144 "{"^NUri.string_of_uri u^"} with "^string_of_int leftno^" fixed params\n"^
146 String.concat "\nand "
147 (List.map (fun (_,name,ty,cl) ->
148 name^": "^ppterm ~metasenv ~subst ~context:[] ty^ " :=\n"^
150 (List.map (fun (_,name,ty) ->
151 " | "^name^": "^ppterm ~metasenv ~subst ~context:[] ty)
153 | (u,_,metasenv,subst,NCic.Constant (_,name,None,ty, _)) ->
154 "{"^NUri.string_of_uri u^"}\n"^
155 "axiom " ^ name ^ " : " ^
156 ppterm ~metasenv ~subst ~context:[] ty ^ "\n"
157 | (u,_,metasenv,subst,NCic.Constant (_,name,Some bo,ty, _)) ->
158 "{"^NUri.string_of_uri u^"}\n"^
159 "definition " ^ name ^ " : " ^
160 ppterm ~metasenv ~subst ~context:[] ty ^ " := \n"^
161 ppterm ~metasenv ~subst ~context:[] bo ^ "\n"