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
76 | Assumption _ -> "assumption"
77 | Change (_, where, with_what) ->
78 sprintf "change %s with %s" (pp_tactic_pattern where) (lazy_term_pp with_what)
79 | Clear (_,id) -> sprintf "clear %s" id
80 | ClearBody (_,id) -> sprintf "clearbody %s" id
81 | Constructor (_,n) -> "constructor " ^ string_of_int n
82 | Contradiction _ -> "contradiction"
83 | Cut (_, ident, term) ->
84 "cut " ^ term_pp term ^
85 (match ident with None -> "" | Some id -> " as " ^ id)
86 | Decompose (_, [], what, names) ->
87 sprintf "decompose %s%s" what (pp_intros_specs (None, names))
88 | Decompose (_, types, what, names) ->
89 let to_ident = function
91 | Type _ -> assert false
93 let types = List.rev_map to_ident types in
94 sprintf "decompose %s %s%s" (pp_idents types) what (pp_intros_specs (None, names))
95 | Discriminate (_, term) -> "discriminate " ^ term_pp term
96 | Elim (_, term, using, num, idents) ->
97 sprintf "elim " ^ term_pp term ^
98 (match using with None -> "" | Some term -> " using " ^ term_pp term)
99 ^ pp_intros_specs (num, idents)
100 | ElimType (_, term, using, num, idents) ->
101 sprintf "elim type " ^ term_pp term ^
102 (match using with None -> "" | Some term -> " using " ^ term_pp term)
103 ^ pp_intros_specs (num, idents)
104 | Exact (_, term) -> "exact " ^ term_pp term
105 | Exists _ -> "exists"
106 | Fold (_, kind, term, pattern) ->
107 sprintf "fold %s %s %s" (pp_reduction_kind kind)
108 (lazy_term_pp term) (pp_tactic_pattern pattern)
109 | FwdSimpl (_, hyp, idents) ->
110 sprintf "fwd %s%s" hyp
111 (match idents with [] -> "" | idents -> " " ^ pp_idents idents)
112 | Generalize (_, pattern, ident) ->
113 sprintf "generalize %s%s" (pp_tactic_pattern pattern)
114 (match ident with None -> "" | Some id -> " as " ^ id)
115 | Goal (_, n) -> "goal " ^ string_of_int n
117 | Fourier _ -> "fourier"
119 | Injection (_, term) -> "injection " ^ term_pp term
120 | Intros (_, None, []) -> "intro"
121 | Inversion (_, term) -> "inversion " ^ term_pp term
122 | Intros (_, num, idents) ->
124 (match num with None -> "" | Some num -> " " ^ string_of_int num)
125 (match idents with [] -> "" | idents -> " " ^ pp_idents idents)
126 | LApply (_, level_opt, terms, term, ident_opt) ->
127 sprintf "lapply %s%s%s%s"
128 (match level_opt with None -> "" | Some i -> " depth = " ^ string_of_int i ^ " ")
130 (match terms with [] -> "" | _ -> " to " ^ terms_pp ~term_pp terms)
131 (match ident_opt with None -> "" | Some ident -> " using " ^ ident)
133 | LetIn (_, term, ident) -> sprintf "let %s in %s" (term_pp term) ident
134 | Reduce (_, kind, pat) ->
135 sprintf "%s %s" (pp_reduction_kind kind) (pp_tactic_pattern pat)
136 | Reflexivity _ -> "reflexivity"
137 | Replace (_, pattern, t) ->
138 sprintf "replace %s with %s" (pp_tactic_pattern pattern) (lazy_term_pp t)
139 | Rewrite (_, pos, t, pattern) ->
140 sprintf "rewrite %s %s %s"
141 (if pos = `LeftToRight then ">" else "<")
143 (pp_tactic_pattern pattern)
147 | Symmetry _ -> "symmetry"
148 | Transitivity (_, term) -> "transitivity " ^ term_pp term
150 let pp_search_kind = function
151 | `Locate -> "locate"
155 | `Instance -> "instance"
157 let pp_arg ~term_pp arg =
158 let s = term_pp arg in
159 if s = "" || (s.[0] = '(' && s.[String.length s - 1] = ')') then
160 (* _nice_ heuristic *)
165 let pp_macro ~term_pp =
166 let term_pp = pp_arg ~term_pp in
169 | WInstance (_, term) -> "whelp instance " ^ term_pp term
170 | WHint (_, t) -> "whelp hint " ^ term_pp t
171 | WLocate (_, s) -> "whelp locate \"" ^ s ^ "\""
172 | WElim (_, t) -> "whelp elim " ^ term_pp t
173 | WMatch (_, term) -> "whelp match " ^ term_pp term
175 | Check (_, term) -> sprintf "Check %s" (term_pp term)
177 | Search_pat (_, kind, pat) ->
178 sprintf "search %s \"%s\"" (pp_search_kind kind) pat
179 | Search_term (_, kind, term) ->
180 sprintf "search %s %s" (pp_search_kind kind) (term_pp term)
181 | Print (_, name) -> sprintf "Print \"%s\"" name
184 let pp_associativity = function
185 | Gramext.LeftA -> "left associative"
186 | Gramext.RightA -> "right associative"
187 | Gramext.NonA -> "non associative"
189 let pp_precedence i = sprintf "with precedence %d" i
191 let pp_dir_opt = function
193 | Some `LeftToRight -> "> "
194 | Some `RightToLeft -> "< "
196 let pp_default what uris =
197 sprintf "default \"%s\" %s" what
198 (String.concat " " (List.map UriManager.string_of_uri uris))
200 let pp_coercion uri do_composites =
201 sprintf "coercion %s (* %s *)" (UriManager.string_of_uri uri)
202 (if do_composites then "compounds" else "no compounds")
204 let pp_command ~obj_pp = function
205 | Include (_,path) -> "include " ^ path
208 | Set (_, name, value) -> sprintf "set \"%s\" \"%s\"" name value
209 | Coercion (_, uri, do_composites) -> pp_coercion uri do_composites
210 | Obj (_,obj) -> obj_pp obj
211 | Default (_,what,uris) ->
214 let rec pp_tactical ~term_pp ~lazy_term_pp =
215 let pp_tactic = pp_tactic ~lazy_term_pp ~term_pp in
216 let pp_tacticals = pp_tacticals ~lazy_term_pp ~term_pp in
218 | Tactic (_, tac) -> pp_tactic tac
219 | Do (_, count, tac) ->
220 sprintf "do %d %s" count (pp_tactical ~term_pp ~lazy_term_pp tac)
221 | Repeat (_, tac) -> "repeat " ^ pp_tactical ~term_pp ~lazy_term_pp tac
222 | Seq (_, tacs) -> pp_tacticals ~sep:"; " tacs
223 | Then (_, tac, tacs) ->
224 sprintf "%s; [%s]" (pp_tactical ~term_pp ~lazy_term_pp tac)
225 (pp_tacticals ~sep:" | " tacs)
226 | First (_, tacs) -> sprintf "tries [%s]" (pp_tacticals ~sep:" | " tacs)
227 | Try (_, tac) -> "try " ^ pp_tactical ~term_pp ~lazy_term_pp tac
228 | Solve (_, tac) -> sprintf "solve [%s]" (pp_tacticals ~sep:" | " tac)
234 | Pos (_, i) -> sprintf "%d:" i
236 | Focus (_, goals) ->
237 sprintf "focus %s" (String.concat " " (List.map string_of_int goals))
238 | Unfocus _ -> "unfocus"
241 and pp_tacticals ~term_pp ~lazy_term_pp ~sep tacs =
242 String.concat sep (List.map (pp_tactical~lazy_term_pp ~term_pp) tacs)
244 let pp_executable ~term_pp ~lazy_term_pp ~obj_pp =
246 | Macro (_, macro) -> pp_macro ~term_pp macro
247 | Tactical (_, tac, Some punct) ->
248 pp_tactical ~lazy_term_pp ~term_pp tac
249 ^ pp_tactical ~lazy_term_pp ~term_pp punct
250 | Tactical (_, tac, None) -> pp_tactical ~lazy_term_pp ~term_pp tac
251 | Command (_, cmd) -> pp_command ~obj_pp cmd
253 let pp_comment ~term_pp ~lazy_term_pp ~obj_pp =
255 | Note (_,str) -> sprintf "(* %s *)" str
257 sprintf "(** %s. **)" (pp_executable ~term_pp ~lazy_term_pp ~obj_pp code)
259 let pp_statement ~term_pp ~lazy_term_pp ~obj_pp =
261 | Executable (_, ex) -> pp_executable ~lazy_term_pp ~term_pp ~obj_pp ex
262 | Comment (_, c) -> pp_comment ~term_pp ~lazy_term_pp ~obj_pp c