]> matita.cs.unibo.it Git - helm.git/blob - helm/ocaml/cic_transformations/cicAstPp.ml
first moogle template checkin
[helm.git] / helm / ocaml / cic_transformations / cicAstPp.ml
1 (* Copyright (C) 2004, HELM Team.
2  * 
3  * This file is part of HELM, an Hypertextual, Electronic
4  * Library of Mathematics, developed at the Computer Science
5  * Department, University of Bologna, Italy.
6  * 
7  * HELM is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  * 
12  * HELM is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with HELM; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
20  * MA  02111-1307, USA.
21  * 
22  * For details, see the HELM World-Wide-Web page,
23  * http://helm.cs.unibo.it/
24  *)
25
26 open Printf
27
28 let pp_binder = function
29   | `Lambda -> "lambda"
30   | `Pi -> "Pi"
31   | `Exists -> "exists"
32   | `Forall -> "forall"
33
34 let pp_name = function Cic.Anonymous -> "_" | Cic.Name s -> s
35
36 let rec pp_term = function
37   | CicAst.AttributedTerm (_, term) -> pp_term term
38
39   | CicAst.Appl terms ->
40       sprintf "(%s)" (String.concat " " (List.map pp_term terms))
41   | CicAst.Binder (`Forall, (Cic.Anonymous, typ), body)
42   | CicAst.Binder (`Pi, (Cic.Anonymous, typ), body) ->
43       sprintf "(%s \\to %s)"
44         (match typ with None -> "?" | Some typ -> pp_term typ)
45         (pp_term body)
46   | CicAst.Binder (kind, var, body) ->
47       sprintf "\\%s %s.%s" (pp_binder kind) (pp_capture_variable var)
48         (pp_term body)
49   | CicAst.Case (term, indtype, typ, patterns) ->
50       sprintf "%smatch %s with %s"
51         (match typ with None -> "" | Some t -> sprintf "<%s>" (pp_term t))
52         (pp_term term) (pp_patterns patterns)
53   | CicAst.LetIn (var, t1, t2) ->
54       sprintf "let %s = %s in %s" (pp_capture_variable var) (pp_term t1)
55         (pp_term t2)
56   | CicAst.LetRec (kind, definitions, term) ->
57       sprintf "let %s %s in %s"
58         (match kind with `Inductive -> "rec" | `CoInductive -> "corec")
59         (String.concat " and "
60           (List.map
61             (fun (var, body, _) ->
62               sprintf "%s = %s" (pp_capture_variable var) (pp_term body))
63             definitions))
64         (pp_term term)
65   | CicAst.Ident (name, Some [])
66   | CicAst.Ident (name, None) ->
67       name
68   | CicAst.Ident (name, Some substs) -> sprintf "%s \\subst [%s]" name (pp_substs substs)
69   | CicAst.Implicit -> "?"
70   | CicAst.Meta (index, substs) ->
71       sprintf "%d[%s]" index
72         (String.concat "; "
73           (List.map (function None -> "_" | Some term -> pp_term term) substs))
74   | CicAst.Num (num, _) -> num
75   | CicAst.Sort `Set -> "Set"
76   | CicAst.Sort `Prop -> "Prop"
77   | CicAst.Sort `Type -> "Type"
78   | CicAst.Sort `CProp -> "CProp"
79   | CicAst.Symbol (name, _) -> name
80
81 and pp_subst (name, term) = sprintf "%s \\Assign %s" name (pp_term term)
82 and pp_substs substs = String.concat "; " (List.map pp_subst substs)
83
84 and pp_pattern ((head, vars), term) =
85   sprintf "%s \Rightarrow %s"
86     (match vars with
87     | [] -> head
88     | _ ->
89         sprintf "(%s %s)" head
90           (String.concat " " (List.map pp_capture_variable vars)))
91     (pp_term term)
92
93 and pp_patterns patterns =
94   sprintf "[%s]" (String.concat " | " (List.map pp_pattern patterns))
95
96 and pp_capture_variable = function
97   | name, None -> pp_name name
98   | name, Some typ -> "(" ^ pp_name name ^ ": " ^ pp_term typ ^ ")"
99