]> matita.cs.unibo.it Git - helm.git/blob - helm/ocaml/cic_transformations/tacticAstPp.ml
merged changes from the svn fork by me and Enrico
[helm.git] / helm / ocaml / cic_transformations / tacticAstPp.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 open TacticAst
29
30 let tactical_terminator = "."
31 let tactic_terminator = tactical_terminator
32 let tactical_separator = ";"
33
34 let pp_term_ast term = CicAstPp.pp_term term
35 let pp_term_cic term = CicPp.ppterm term
36
37 let pp_idents idents = "[" ^ String.concat "; " idents ^ "]"
38
39 let pp_reduction_kind = function
40   | `Reduce -> "reduce"
41   | `Simpl -> "simplify"
42   | `Whd -> "whd"
43
44 let rec pp_tactic = function
45   | Absurd (_, term) -> "absurd" ^ pp_term_ast term
46   | Apply (_, term) -> "apply " ^ pp_term_ast term
47   | Auto _ -> "auto"
48   | Assumption _ -> "assumption"
49   | Change (_, t1, t2, where) ->
50       sprintf "change %s with %s%s" (pp_term_ast t1) (pp_term_ast t2)
51         (match where with None -> "" | Some ident -> "in " ^ ident)
52   | Change_pattern (_, _, _, _) -> assert false  (* TODO *)
53   | Contradiction _ -> "contradiction"
54   | Cut (_, term) -> "cut " ^ pp_term_ast term
55   | Decompose (_, ident, principles) ->
56       sprintf "decompose %s %s" (pp_idents principles) ident
57   | Discriminate (_, ident) -> "discriminate " ^ ident
58   | Elim (_, term, using) ->
59       sprintf "elim " ^ pp_term_ast term ^
60       (match using with None -> "" | Some term -> " using " ^ pp_term_ast term)
61   | ElimType (_, term) -> "elim type " ^ pp_term_ast term
62   | Exact (_, term) -> "exact " ^ pp_term_ast term
63   | Exists _ -> "exists"
64   | Fold (_, kind, term) ->
65       sprintf "fold %s %s" (pp_reduction_kind kind) (pp_term_ast term)
66   | Goal (_, n) -> "goal " ^ string_of_int n
67   | Fourier _ -> "fourier"
68   | Hint _ -> "hint"
69   | Injection (_, ident) -> "injection " ^ ident
70   | Intros (_, None, []) -> "intro"
71   | Intros (_, num, idents) ->
72       sprintf "intros%s%s"
73         (match num with None -> "" | Some num -> " " ^ string_of_int num)
74         (match idents with [] -> "" | idents -> " " ^ pp_idents idents)
75   | Left _ -> "left"
76   | LetIn (_, term, ident) -> sprintf "let %s in %s" (pp_term_ast term) ident
77   | Reduce (_, kind, None)
78   | Reduce (_, kind, Some ([], `Goal)) -> pp_reduction_kind kind
79   | Reduce (_, kind, Some ([], `Everywhere)) ->
80       sprintf "%s in hyp" (pp_reduction_kind kind)
81   | Reduce (_, kind, Some (terms, `Goal)) ->
82       sprintf "%s %s" (pp_reduction_kind kind)
83         (String.concat ", " (List.map pp_term_ast terms))
84   | Reduce (_, kind, Some (terms, `Everywhere)) ->
85       sprintf "%s in hyp %s" (pp_reduction_kind kind)
86         (String.concat ", " (List.map pp_term_ast terms))
87   | Reflexivity _ -> "reflexivity"
88   | Replace (_, t1, t2) ->
89       sprintf "replace %s with %s" (pp_term_ast t1) (pp_term_ast t2)
90   | Replace_pattern (_, _, _) -> assert false  (* TODO *)
91   | Rewrite (_, _, _, _) -> assert false (* TODO *)
92   | Right _ -> "right"
93   | Ring _ -> "ring"
94   | Split _ -> "split"
95   | Symmetry _ -> "symmetry"
96   | Transitivity (_, term) -> "transitivity " ^ pp_term_ast term
97
98 let pp_flavour = function
99   | `Definition -> "Definition"
100   | `Fact -> "Fact"
101   | `Goal -> "Goal"
102   | `Lemma -> "Lemma"
103   | `Remark -> "Remark"
104   | `Theorem -> "Theorem"
105
106 let pp_search_kind = function
107   | `Locate -> "locate"
108   | `Hint -> "hint"
109   | `Match -> "match"
110   | `Elim -> "elim"
111
112 let pp_macro pp_term = function 
113   | Abort _ -> "Abort"
114   | Check (_, term) -> sprintf "Check %s" (pp_term term)
115   | Redo (_, None) -> "Redo"
116   | Redo (_, Some n) -> sprintf "Redo %d" n
117   | Search_pat (_, kind, pat) ->
118       sprintf "search %s \"%s\"" (pp_search_kind kind) pat
119   | Search_term (_, kind, term) ->
120       sprintf "search %s %s" (pp_search_kind kind) (pp_term term)
121   | Undo (_, None) -> "Undo"
122   | Undo (_, Some n) -> sprintf "Undo %d" n
123   | Print (_, name) -> sprintf "Print \"%s\"" name
124   | Quit _ -> "Quit"
125
126 let pp_macro_ast = pp_macro pp_term_ast
127 let pp_macro_cic = pp_macro pp_term_cic
128
129 let pp_alias = function
130   | Ident_alias (id, uri) -> sprintf "alias id \"%s\" = \"%s\"" id uri
131   | Symbol_alias (symb, instance, desc) ->
132       sprintf "alias symbol \"%s\" (instance %d) = \"%s\""
133         symb instance desc
134   | Number_alias (instance,desc) ->
135       sprintf "alias num (instance %d) = \"%s\"" instance desc
136   
137 let pp_command = function
138   | Qed _ -> "Qed"
139   | Set (_, name, value) -> sprintf "Set \"%s\" \"%s\"" name value
140   | Inductive (_, params, types) ->
141       let pp_params = function
142         | [] -> ""
143         | params ->
144             " " ^
145             String.concat " "
146               (List.map
147                 (fun (name, typ) -> sprintf "(%s:%s)" name (pp_term_ast typ))
148                 params)
149       in
150       let pp_constructors constructors =
151         String.concat "\n"
152           (List.map (fun (name, typ) -> sprintf "| %s: %s" name (pp_term_ast typ))
153             constructors)
154       in
155       let pp_type (name, _, typ, constructors) =
156         sprintf "\nwith %s: %s \\def\n%s" name (pp_term_ast typ)
157           (pp_constructors constructors)
158       in
159       (match types with
160       | [] -> assert false
161       | (name, inductive, typ, constructors) :: tl ->
162           let fst_typ_pp =
163             sprintf "%sinductive %s%s: %s \\def\n%s"
164               (if inductive then "" else "co") name (pp_params params)
165               (pp_term_ast typ) (pp_constructors constructors)
166           in
167           fst_typ_pp ^ String.concat "" (List.map pp_type tl))
168   | Theorem (_, flavour, name, typ, body) ->
169       sprintf "%s %s: %s %s"
170         (pp_flavour flavour)
171         (match name with None -> "" | Some name -> name)
172         (pp_term_ast typ)
173         (match body with
174         | None -> ""
175         | Some body -> "\\def " ^ pp_term_ast body)
176   | Coercion (_,_) -> "Coercion IMPLEMENT ME!!!!!"
177   | Alias (_,s) -> pp_alias s
178
179 let rec pp_tactical = function
180   | Tactic (_, tac) -> pp_tactic tac
181
182   | Fail _ -> "fail"
183   | Do (_, count, tac) -> sprintf "do %d %s" count (pp_tactical tac)
184   | IdTac _ -> "id"
185   | Repeat (_, tac) -> "repeat " ^ pp_tactical tac
186   | Seq (_, tacs) -> pp_tacticals tacs
187   | Then (_, tac, tacs) ->
188       sprintf "%s [%s]" (pp_tactical tac) (pp_tacticals tacs)
189   | Tries (_, tacs) -> sprintf "tries [%s]" (pp_tacticals tacs)
190   | Try (_, tac) -> "try " ^ pp_tactical tac
191
192 and pp_tacticals tacs =
193   String.concat (tactical_separator ^ " ") (List.map pp_tactical tacs)
194
195 let pp_tactical tac = pp_tactical tac ^ tactical_terminator
196 let pp_tactic tac = pp_tactic tac ^ tactic_terminator
197