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/
32 let tactical_terminator = ""
33 let tactic_terminator = tactical_terminator
34 let command_terminator = tactical_terminator
36 let pp_idents idents = "[" ^ String.concat "; " idents ^ "]"
38 let pp_reduction_kind ~term_pp = function
39 | `Demodulate -> "demodulate"
40 | `Normalize -> "normalize"
42 | `Simpl -> "simplify"
43 | `Unfold (Some t) -> "unfold " ^ term_pp t
44 | `Unfold None -> "unfold"
47 let pp_tactic_pattern ~term_pp ~lazy_term_pp (what, hyp, goal) =
51 | Some t -> sprintf "in match (%s) " (lazy_term_pp t) in
54 (List.map (fun (name, p) -> sprintf "%s:(%s)" name (term_pp p)) hyp) in
58 | Some t -> sprintf "\\vdash (%s)" (term_pp t) in
59 sprintf "%sin %s%s" what_text hyp_text goal_text
61 let pp_intros_specs = function
63 | Some num, [] -> Printf.sprintf " names %i" num
64 | None, idents -> Printf.sprintf " names %s" (pp_idents idents)
65 | Some num, idents -> Printf.sprintf " names %i %s" num (pp_idents idents)
67 let terms_pp ~term_pp terms = String.concat ", " (List.map term_pp terms)
69 let rec pp_tactic ~term_pp ~lazy_term_pp =
70 let pp_reduction_kind = pp_reduction_kind ~term_pp in
71 let pp_tactic_pattern = pp_tactic_pattern ~lazy_term_pp ~term_pp in
73 | Absurd (_, term) -> "absurd" ^ term_pp term
74 | Apply (_, term) -> "apply " ^ term_pp term
75 | ApplyS (_, term) -> "applyS " ^ term_pp term
76 | Auto (_,params) -> "auto " ^
78 (List.map (fun (k,v) -> if v <> "" then k ^ "=" ^ v else k) params)
79 | Assumption _ -> "assumption"
80 | Change (_, where, with_what) ->
81 sprintf "change %s with %s" (pp_tactic_pattern where) (lazy_term_pp with_what)
82 | Clear (_,id) -> sprintf "clear %s" id
83 | ClearBody (_,id) -> sprintf "clearbody %s" id
84 | Constructor (_,n) -> "constructor " ^ string_of_int n
85 | Contradiction _ -> "contradiction"
86 | Cut (_, ident, term) ->
87 "cut " ^ term_pp term ^
88 (match ident with None -> "" | Some id -> " as " ^ id)
89 | Decompose (_, [], what, names) ->
90 sprintf "decompose %s%s" what (pp_intros_specs (None, names))
91 | Decompose (_, types, what, names) ->
92 let to_ident = function
94 | Type _ -> assert false
96 let types = List.rev_map to_ident types in
97 sprintf "decompose %s %s%s" (pp_idents types) what (pp_intros_specs (None, names))
98 | Discriminate (_, term) -> "discriminate " ^ term_pp term
99 | Elim (_, term, using, num, idents) ->
100 sprintf "elim " ^ term_pp term ^
101 (match using with None -> "" | Some term -> " using " ^ term_pp term)
102 ^ pp_intros_specs (num, idents)
103 | ElimType (_, term, using, num, idents) ->
104 sprintf "elim type " ^ term_pp term ^
105 (match using with None -> "" | Some term -> " using " ^ term_pp term)
106 ^ pp_intros_specs (num, idents)
107 | Exact (_, term) -> "exact " ^ term_pp term
108 | Exists _ -> "exists"
109 | Fold (_, kind, term, pattern) ->
110 sprintf "fold %s %s %s" (pp_reduction_kind kind)
111 (lazy_term_pp term) (pp_tactic_pattern pattern)
112 | FwdSimpl (_, hyp, idents) ->
113 sprintf "fwd %s%s" hyp
114 (match idents with [] -> "" | idents -> " as " ^ pp_idents idents)
115 | Generalize (_, pattern, ident) ->
116 sprintf "generalize %s%s" (pp_tactic_pattern pattern)
117 (match ident with None -> "" | Some id -> " as " ^ id)
118 | Goal (_, n) -> "goal " ^ string_of_int n
120 | Fourier _ -> "fourier"
122 | Injection (_, term) -> "injection " ^ term_pp term
123 | Intros (_, None, []) -> "intros"
124 | Inversion (_, term) -> "inversion " ^ term_pp term
125 | Intros (_, num, idents) ->
127 (match num with None -> "" | Some num -> " " ^ string_of_int num)
128 (match idents with [] -> "" | idents -> " " ^ pp_idents idents)
129 | LApply (_, level_opt, terms, term, ident_opt) ->
130 sprintf "lapply %s%s%s%s"
131 (match level_opt with None -> "" | Some i -> " depth = " ^ string_of_int i ^ " ")
133 (match terms with [] -> "" | _ -> " to " ^ terms_pp ~term_pp terms)
134 (match ident_opt with None -> "" | Some ident -> " as " ^ ident)
136 | LetIn (_, term, ident) -> sprintf "let %s in %s" (term_pp term) ident
137 | Reduce (_, kind, pat) ->
138 sprintf "%s %s" (pp_reduction_kind kind) (pp_tactic_pattern pat)
139 | Reflexivity _ -> "reflexivity"
140 | Replace (_, pattern, t) ->
141 sprintf "replace %s with %s" (pp_tactic_pattern pattern) (lazy_term_pp t)
142 | Rewrite (_, pos, t, pattern) ->
143 sprintf "rewrite %s %s %s"
144 (if pos = `LeftToRight then ">" else "<")
146 (pp_tactic_pattern pattern)
150 | Symmetry _ -> "symmetry"
151 | Transitivity (_, term) -> "transitivity " ^ term_pp term
153 let pp_search_kind = function
154 | `Locate -> "locate"
158 | `Instance -> "instance"
160 let pp_arg ~term_pp arg =
161 let s = term_pp arg in
162 if s = "" || (s.[0] = '(' && s.[String.length s - 1] = ')') then
163 (* _nice_ heuristic *)
168 let pp_macro ~term_pp =
169 let term_pp = pp_arg ~term_pp in
172 | WInstance (_, term) -> "whelp instance " ^ term_pp term
173 | WHint (_, t) -> "whelp hint " ^ term_pp t
174 | WLocate (_, s) -> "whelp locate \"" ^ s ^ "\""
175 | WElim (_, t) -> "whelp elim " ^ term_pp t
176 | WMatch (_, term) -> "whelp match " ^ term_pp term
178 | Check (_, term) -> sprintf "Check %s" (term_pp term)
180 | Search_pat (_, kind, pat) ->
181 sprintf "search %s \"%s\"" (pp_search_kind kind) pat
182 | Search_term (_, kind, term) ->
183 sprintf "search %s %s" (pp_search_kind kind) (term_pp term)
184 | Print (_, name) -> sprintf "Print \"%s\"" name
187 let pp_associativity = function
188 | Gramext.LeftA -> "left associative"
189 | Gramext.RightA -> "right associative"
190 | Gramext.NonA -> "non associative"
192 let pp_precedence i = sprintf "with precedence %d" i
194 let pp_dir_opt = function
196 | Some `LeftToRight -> "> "
197 | Some `RightToLeft -> "< "
199 let pp_default what uris =
200 sprintf "default \"%s\" %s" what
201 (String.concat " " (List.map UriManager.string_of_uri uris))
203 let pp_coercion uri do_composites =
204 sprintf "coercion %s (* %s *)" (UriManager.string_of_uri uri)
205 (if do_composites then "compounds" else "no compounds")
207 let pp_command ~obj_pp = function
208 | Include (_,path) -> "include \"" ^ path ^ "\""
211 | Set (_, name, value) -> sprintf "set \"%s\" \"%s\"" name value
212 | Coercion (_, uri, do_composites) -> pp_coercion uri do_composites
213 | Obj (_,obj) -> obj_pp obj
214 | Default (_,what,uris) ->
217 let rec pp_tactical ~term_pp ~lazy_term_pp =
218 let pp_tactic = pp_tactic ~lazy_term_pp ~term_pp in
219 let pp_tacticals = pp_tacticals ~lazy_term_pp ~term_pp in
221 | Tactic (_, tac) -> pp_tactic tac
222 | Do (_, count, tac) ->
223 sprintf "do %d %s" count (pp_tactical ~term_pp ~lazy_term_pp tac)
224 | Repeat (_, tac) -> "repeat " ^ pp_tactical ~term_pp ~lazy_term_pp tac
225 | Seq (_, tacs) -> pp_tacticals ~sep:"; " tacs
226 | Then (_, tac, tacs) ->
227 sprintf "%s; [%s]" (pp_tactical ~term_pp ~lazy_term_pp tac)
228 (pp_tacticals ~sep:" | " tacs)
229 | First (_, tacs) -> sprintf "tries [%s]" (pp_tacticals ~sep:" | " tacs)
230 | Try (_, tac) -> "try " ^ pp_tactical ~term_pp ~lazy_term_pp tac
231 | Solve (_, tac) -> sprintf "solve [%s]" (pp_tacticals ~sep:" | " tac)
237 | Pos (_, i) -> sprintf "%s:" (String.concat "," (List.map string_of_int i))
240 | Focus (_, goals) ->
241 sprintf "focus %s" (String.concat " " (List.map string_of_int goals))
242 | Unfocus _ -> "unfocus"
245 and pp_tacticals ~term_pp ~lazy_term_pp ~sep tacs =
246 String.concat sep (List.map (pp_tactical~lazy_term_pp ~term_pp) tacs)
248 let pp_executable ~term_pp ~lazy_term_pp ~obj_pp =
250 | Macro (_, macro) -> pp_macro ~term_pp macro ^ "."
251 | Tactical (_, tac, Some punct) ->
252 pp_tactical ~lazy_term_pp ~term_pp tac
253 ^ pp_tactical ~lazy_term_pp ~term_pp punct
254 | Tactical (_, tac, None) -> pp_tactical ~lazy_term_pp ~term_pp tac
255 | Command (_, cmd) -> pp_command ~obj_pp cmd ^ "."
257 let pp_comment ~term_pp ~lazy_term_pp ~obj_pp =
259 | Note (_,str) -> sprintf "(* %s *)" str
261 sprintf "(** %s. **)" (pp_executable ~term_pp ~lazy_term_pp ~obj_pp code)
263 let pp_statement ~term_pp ~lazy_term_pp ~obj_pp =
265 | Executable (_, ex) -> pp_executable ~lazy_term_pp ~term_pp ~obj_pp ex
266 | Comment (_, c) -> pp_comment ~term_pp ~lazy_term_pp ~obj_pp c