1 (* Copyright (C) 2004, HELM Team.
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.
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.
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.
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,
22 * For details, see the HELM World-Wide-Web page,
23 * http://helm.cs.unibo.it/
26 open CicTextualParser2Ast
29 let pp_binder = function
35 let pp_name = function Cic.Anonymous -> "_" | Cic.Name s -> s
36 let rec pp_capture_variable = function
37 | name, None -> pp_name name
38 | name, Some typ -> "(" ^ pp_name name ^ ": " ^ pp_term typ ^ ")"
39 and pp_term = function
40 | AttributedTerm (_, term) -> pp_term term
42 | Appl terms -> sprintf "(%s)" (String.concat " " (List.map pp_term terms))
43 | Appl_symbol (symbol, _, terms) ->
44 sprintf "(%s %s)" symbol (String.concat " " (List.map pp_term terms))
45 | Binder (kind, var, body) ->
46 sprintf "\\%s %s.%s" (pp_binder kind) (pp_capture_variable var)
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 (var, t1, t2) ->
53 sprintf "let %s = %s in %s" (pp_capture_variable var) (pp_term t1)
55 | LetRec (kind, definitions, term) ->
56 sprintf "let %s %s in %s"
57 (match kind with `Inductive -> "rec" | `CoInductive -> "corec")
58 (String.concat " and "
60 (fun (var, body, _) ->
61 sprintf "%s = %s" (pp_capture_variable var) (pp_term body))
64 | Ident (name, []) -> name
65 | Ident (name, substs) -> sprintf "%s[%s]" name (pp_substs substs)
66 | Meta (index, substs) ->
67 sprintf "%d[%s]" index
69 (List.map (function None -> "_" | Some term -> pp_term term) substs))
72 | Sort `Prop -> "Prop"
73 | Sort `Type -> "Type"
74 | Sort `CProp -> "CProp"
76 and pp_subst (name, term) = sprintf "%s := %s" name (pp_term term)
77 and pp_substs substs = String.concat "; " (List.map pp_subst substs)
79 and pp_pattern ((head, vars), term) =
84 sprintf "(%s %s)" head
85 (String.concat " " (List.map pp_capture_variable vars)))
88 and pp_patterns patterns =
89 sprintf "[%s]" (String.concat " | " (List.map pp_pattern patterns))