]> matita.cs.unibo.it Git - helm.git/blob - helm/ocaml/cic_disambiguation/pp.ml
still a working copy, now towards a cleaner implementation ...
[helm.git] / helm / ocaml / cic_disambiguation / pp.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 Ast
27 open Printf
28
29 let pp_binder = function
30   | `Lambda -> "lambda"
31   | `Pi -> "pi"
32   | `Exists -> "exists"
33   | `Forall -> "forall"
34
35 let rec pp_term = function
36   | LocatedTerm ((p_begin, p_end), term) ->
37 (*       sprintf "[%d,%d]%s" p_begin p_end (pp_term term) *)
38       pp_term term
39
40   | Appl terms -> sprintf "(%s)" (String.concat " " (List.map pp_term terms))
41   | Appl_symbol (symbol, terms) ->
42       sprintf "(%s %s)" symbol (String.concat " " (List.map pp_term terms))
43   | Binder (kind, var, typ, body) ->
44       sprintf "\\%s %s%s.%s" (pp_binder kind)
45         (match var with Cic.Anonymous -> "_" | Cic.Name s -> s)
46         (match typ with None -> "" | Some typ -> ": " ^ pp_term typ)
47         (pp_term body)
48   | Case (term, indtype, typ, patterns) ->
49       sprintf "%smatch %s with %s"
50         (match typ with None -> "" | Some t -> sprintf "<%s>" (pp_term t))
51         (pp_term term) (pp_patterns patterns)
52   | LetIn (name, t1, t2) ->
53       sprintf "let %s = %s in %s" name (pp_term t1) (pp_term t2)
54   | LetRec (kind, definitions, term) ->
55       sprintf "let %s %s in %s"
56         (match kind with `Inductive -> "rec" | `CoInductive -> "corec")
57         (String.concat " and "
58           (List.map
59             (fun (name, body, typ, index) ->
60               sprintf "%s%s = %s" name
61                 (match typ with None -> "" | Some typ -> ": " ^ pp_term typ)
62                 (pp_term body))
63             definitions))
64         (pp_term term)
65   | Ident (name, []) -> name
66   | Ident (name, substs) -> sprintf "%s[%s]" name (pp_substs substs)
67   | Meta (index, substs) ->
68       sprintf "%d[%s]" index
69         (String.concat "; "
70           (List.map (function None -> "_" | Some term -> pp_term term) substs))
71   | Num num -> num
72   | Sort `Set -> "Set"
73   | Sort `Prop -> "Prop"
74   | Sort `Type -> "Type"
75   | Sort `CProp -> "CProp"
76
77 and pp_subst (name, term) = sprintf "%s := %s" name (pp_term term)
78 and pp_substs substs = String.concat "; " (List.map pp_subst substs)
79
80 and pp_pattern (names, term) =
81   sprintf "%s -> %s"
82     (match names with
83     | [n] -> n
84     | names -> "(" ^ String.concat " " names ^ ")")
85     (pp_term term)
86
87 and pp_patterns patterns =
88   sprintf "[%s]" (String.concat " | " (List.map pp_pattern patterns))
89