]> matita.cs.unibo.it Git - helm.git/blob - helm/software/components/ng_kernel/nCicPp.ml
context, metasenv and subst made mandatory in CicPp
[helm.git] / helm / software / components / ng_kernel / nCicPp.ml
1 let ppterm = 
2   ref (fun ~context ~subst ~metasenv t -> "Please, set a pp callback")
3 ;;
4
5 let set_ppterm f = ppterm := f;;
6
7 let ppterm ~context ~subst ~metasenv t = 
8   !ppterm ~context ~subst ~metasenv t
9 ;;
10
11 module C = NCic
12 module R = NReference
13
14 let trivial_pp_term ~context ~subst ~metasenv = 
15   let rec aux ctx = function
16    | C.Rel m ->
17        (try List.nth ctx (m-1)
18        with Failure _ -> " -" ^ string_of_int (m - List.length context))
19    | C.Const r -> R.string_of_reference r
20    | C.Prod (name,s,t) -> "(\Pi "^name^":"^aux ctx s^"."^aux (name::ctx) t^")"
21    | C.Lambda (name,s,t) -> 
22       "(\lambda "^name^":"^aux ctx s^"."^aux (name::ctx) t^")"
23    | C.LetIn (name,ty,t,b) -> 
24       "(let "^name^":"^aux ctx ty^":="^aux ctx t^" in "^aux (name::ctx) b^")"
25    | C.Match (_,oty,t,pl) ->
26       " match " ^ aux ctx t ^ " return " ^ aux ctx oty ^ "[" ^
27       String.concat "|" (List.map (aux ctx) pl) ^ "]"
28    | C.Appl l -> "("^String.concat " " (List.map (aux ctx) l) ^")"
29    | C.Implicit _ -> "?"
30    | C.Meta (n,_) -> "?"^string_of_int n
31    | C.Sort C.Prop -> "Prop"
32    | C.Sort C.CProp -> "CProp"
33    | C.Sort (C.Type n) -> "Type"^string_of_int n
34   in 
35    aux (List.map fst context)
36 ;;
37
38 let ppobj = function
39   | (u,_,metasenv,subst,NCic.Fixpoint (b, fl, _)) -> 
40        "let rec "^NUri.string_of_uri u^"\n"^
41        String.concat "\nand "
42         (List.map (fun (_,name,n,ty,bo) ->
43           name ^ " on " ^ string_of_int n ^ " : " ^ 
44           ppterm ~metasenv ~subst ~context:[] ty ^ " :=\n"^
45           ppterm ~metasenv ~subst ~context:[] bo) fl)
46   | (u,_,_,_,NCic.Inductive (b, _,tl, _)) -> "inductive"
47   | (u,_,_,_,NCic.Constant (_,_,_, _, _)) -> "constant"
48 ;;
49
50
51