]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/software/components/ng_kernel/nCicPp.ml
Use seed to avoid further name clashes.
[helm.git] / helm / software / components / ng_kernel / nCicPp.ml
index a792e865d060dfdca75eda3b28b01d09427e1930..2c46fef6f18a75874ff5486c71f2e107a96528ec 100644 (file)
@@ -1 +1,55 @@
-let ppterm t = "TODO";;
+let ppterm = 
+  ref (fun ~context ~subst ~metasenv t -> "Please, set a pp callback")
+;;
+
+let set_ppterm f = ppterm := f;;
+
+let ppterm ~context ~subst ~metasenv t = 
+  !ppterm ~context ~subst ~metasenv t
+;;
+
+module C = NCic
+module R = NReference
+
+let trivial_pp_term ~context ~subst ~metasenv = 
+  let rec aux ctx = function
+   | C.Rel m ->
+       (try List.nth ctx (m-1)
+       with Failure _ -> " -" ^ string_of_int (m - List.length context))
+   | C.Const r -> R.string_of_reference r
+   | C.Prod (name,s,t) -> "(\Pi "^name^":"^aux ctx s^"."^aux (name::ctx) t^")"
+   | C.Lambda (name,s,t) -> 
+      "(\lambda "^name^":"^aux ctx s^"."^aux (name::ctx) t^")"
+   | C.LetIn (name,ty,t,b) -> 
+      "(let "^name^":"^aux ctx ty^":="^aux ctx t^" in "^aux (name::ctx) b^")"
+   | C.Match (_,oty,t,pl) ->
+      " match " ^ aux ctx t ^ " return " ^ aux ctx oty ^ "[" ^
+      String.concat "|" (List.map (aux ctx) pl) ^ "]"
+   | C.Appl l -> "("^String.concat " " (List.map (aux ctx) l) ^")"
+   | C.Implicit _ -> "?"
+   | C.Meta (n,_) -> "?"^string_of_int n
+   | C.Sort C.Prop -> "Prop"
+   | C.Sort C.CProp -> "CProp"
+   | C.Sort (C.Type n) -> "Type"^string_of_int n
+  in 
+   aux (List.map fst context)
+;;
+
+let ppobj = function
+  | (u,_,metasenv,subst,NCic.Fixpoint (b, fl, _)) -> 
+       NUri.string_of_uri u^"\n"^
+       "let rec "^
+       String.concat "\nand "
+        (List.map (fun (_,name,n,ty,bo) ->
+          name ^ " on " ^ string_of_int n ^ " : " ^ 
+          ppterm ~metasenv ~subst ~context:[] ty ^ " :=\n"^
+          ppterm ~metasenv ~subst ~context:[] bo) fl)
+  | (u,_,_,_,NCic.Inductive (b, _,tyl, _)) -> "inductive"
+  | (u,_,metasenv,subst,NCic.Constant (_,name,None,ty, _)) -> 
+        "axiom " ^ name ^ " : " ^ 
+          ppterm ~metasenv ~subst ~context:[] ty ^ "\n"
+  | (u,_,metasenv,subst,NCic.Constant (_,name,Some bo,ty, _)) ->
+        "definition " ^ name ^ " : " ^ 
+          ppterm ~metasenv ~subst ~context:[] ty ^ ":=\n"^
+          ppterm ~metasenv ~subst ~context:[] bo ^ "\n"
+;;