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