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