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/
31 let tactical_terminator = ""
32 let tactic_terminator = tactical_terminator
33 let command_terminator = tactical_terminator
35 let pp_tactic_pattern status ~map_unicode_to_tex (what, hyp, goal) =
36 if what = None && hyp = [] && goal = None then "" else
40 | Some t -> Printf.sprintf "in match (%s) " (NotationPp.pp_term status t) in
43 (List.map (fun (name, p) -> Printf.sprintf "%s:(%s)" name
44 (NotationPp.pp_term status p)) hyp) in
49 let vdash = if map_unicode_to_tex then "\\vdash" else "⊢" in
50 Printf.sprintf "%s (%s)" vdash (NotationPp.pp_term status t)
52 Printf.sprintf "%sin %s%s" what_text hyp_text goal_text
54 let pp_auto_params params status =
56 | (None,flags) -> String.concat " " (List.map (fun a,b -> a ^ "=" ^ b) flags)
57 | (Some l,flags) -> (String.concat "," (List.map (NotationPp.pp_term status) l)) ^
58 String.concat " " (List.map (fun a,b -> a ^ "=" ^ b) flags)
61 let pp_just status just =
63 `Term term -> "exact " ^ NotationPp.pp_term status term
64 | `Auto params -> pp_auto_params params status
67 let rec pp_ntactic status ~map_unicode_to_tex =
68 let pp_tactic_pattern = pp_tactic_pattern ~map_unicode_to_tex in
70 | NApply (_,t) -> "@" ^ NotationPp.pp_term status t
71 | NSmartApply (_,t) -> "fixme"
72 | NAuto (_,(None,flgs)) ->
74 String.concat " " (List.map (fun a,b -> a ^ "=" ^ b) flgs)
75 | NAuto (_,(Some l,flgs)) ->
76 "nautobatch" ^ " by " ^
77 (String.concat "," (List.map (NotationPp.pp_term status) l)) ^
78 String.concat " " (List.map (fun a,b -> a ^ "=" ^ b) flgs)
79 | NCases (_,what,where) -> "ncases " ^ NotationPp.pp_term status what ^
80 "...to be implemented..." ^ " " ^ "...to be implemented..."
81 | NConstructor (_,None,l) -> "@ " ^
82 String.concat " " (List.map (NotationPp.pp_term status) l)
83 | NConstructor (_,Some x,l) -> "@" ^ string_of_int x ^ " " ^
84 String.concat " " (List.map (NotationPp.pp_term status) l)
85 | NCase1 (_,n) -> "*" ^ n ^ ":"
86 | NChange (_,what,wwhat) -> "nchange " ^ "...to be implemented..." ^
87 " with " ^ NotationPp.pp_term status wwhat
88 | NCut (_,t) -> "ncut " ^ NotationPp.pp_term status t
89 (*| NDiscriminate (_,t) -> "ndiscriminate " ^ NotationPp.pp_term status t
90 | NSubst (_,t) -> "nsubst " ^ NotationPp.pp_term status t *)
91 | NClear (_,l) -> "nclear " ^ String.concat " " l
92 | NDestruct (_,dom,skip) -> "ndestruct ..."
93 | NElim (_,what,where) -> "nelim " ^ NotationPp.pp_term status what ^
94 "...to be implemented..." ^ " " ^ "...to be implemented..."
96 | NIntro (_,n) -> "#" ^ n
97 | NIntros (_,l) -> "#" ^ String.concat " " l
98 | NInversion (_,what,where) -> "ninversion " ^ NotationPp.pp_term status what ^
99 "...to be implemented..." ^ " " ^ "...to be implemented..."
100 | NLApply (_,t) -> "lapply " ^ NotationPp.pp_term status t
101 | NRewrite (_,dir,n,where) -> "nrewrite " ^
102 (match dir with `LeftToRight -> ">" | `RightToLeft -> "<") ^
103 " " ^ NotationPp.pp_term status n ^ " " ^ pp_tactic_pattern status where
104 | NReduce _ | NGeneralize _ | NLetIn _ | NAssert _ -> "TO BE IMPLEMENTED"
106 | NSemicolon _ -> ";"
109 | NPos (_, l) -> String.concat "," (List.map string_of_int l)^ ":"
110 | NPosbyname (_, s) -> s ^ ":"
111 | NWildcard _ -> "*:"
114 Printf.sprintf "focus %s"
115 (String.concat " " (List.map string_of_int l))
116 | NUnfocus _ -> "unfocus"
118 | NTry (_,tac) -> "ntry " ^ pp_ntactic status ~map_unicode_to_tex tac
119 | NAssumption _ -> "nassumption"
121 "(" ^ String.concat " " (List.map (pp_ntactic status ~map_unicode_to_tex) l)^ ")"
122 | NRepeat (_,t) -> "nrepeat " ^ pp_ntactic status ~map_unicode_to_tex t
123 | Assume (_, ident, term, term1) -> "assume" ^ ident ^ ":" ^ NotationPp.pp_term status term ^
124 (match term1 with None -> " " | Some t1 -> " that is eqivalent to " ^ NotationPp.pp_term status t1)
125 | Suppose (_,term,ident,term1) -> "suppose" ^ NotationPp.pp_term status term ^ "(" ^ ident ^ ")" ^ (match
126 term1 with None -> " " | Some t -> " that is equivalent to " ^ NotationPp.pp_term status t)
127 | By_just_we_proved (_, just, term1, ident, term2) -> pp_just status just ^ "we proved" ^
128 NotationPp.pp_term status term1 ^ (match ident with None -> "" | Some ident -> "(" ^ident^ ")") ^ (match
129 term2 with None -> " " | Some term2 -> " that is equivalent to " ^ NotationPp.pp_term status term2)
130 | We_need_to_prove (_,term,ident,term1) -> "we need to prove" ^ NotationPp.pp_term status term ^
131 (match ident with None -> " " | Some id -> "(" ^ id ^ ")") ^ (match term1 with None -> " " | Some t1
132 -> "or equivalently" ^ NotationPp.pp_term status t1)
133 | Bydone (_, just) -> pp_just status just ^ "done"
134 | ExistsElim (_, just, ident, term, term1, ident1) -> pp_just status just ^ "let " ^ ident ^ ":"
135 ^ NotationPp.pp_term status term ^ "such that " ^ NotationPp.pp_term status term1 ^ "(" ^ ident1 ^ ")"
136 | AndElim (_, just, term1, ident1, term2, ident2) -> pp_just status just ^ "we have " ^
137 NotationPp.pp_term status term1 ^ " (" ^ ident1 ^ ") " ^ "and " ^ NotationPp.pp_term status term2
138 ^ " (" ^ ident2 ^ ")"
139 | Thesisbecomes (_, term1, term2) -> "the thesis becomes " ^ NotationPp.pp_term status term1 ^ (match
140 term2 with None -> " " | Some term2 -> NotationPp.pp_term status term2)
141 | RewritingStep (_, term, term1, term2, cont) ->
144 | Some (None,term) -> "conclude " ^ NotationPp.pp_term status term
145 | Some (Some name,term) ->
146 "obtain (" ^ name ^ ") " ^ NotationPp.pp_term status term)
148 NotationPp.pp_term status term1 ^
150 | `Auto params -> pp_auto_params (None,params) status
151 | `Term term2 -> " exact " ^ NotationPp.pp_term status term2
153 | `SolveWith term -> " using " ^ NotationPp.pp_term status term)
154 ^ (if cont then " done" else "")
157 let pp_nmacro status = function
158 | NCheck (_, term) -> Printf.sprintf "ncheck %s" (NotationPp.pp_term status term)
159 | Screenshot (_, name) -> Printf.sprintf "screenshot \"%s\"" name
162 let pp_l1_pattern = NotationPp.pp_term
163 let pp_l2_pattern = NotationPp.pp_term
165 let pp_alias = function
166 | Ident_alias (id, uri) -> sprintf "alias id \"%s\" = \"%s\"." id uri
167 | Symbol_alias (symb, instance, desc) ->
168 sprintf "alias symbol \"%s\" %s= \"%s\"."
170 (if instance=0 then "" else "(instance "^ string_of_int instance ^ ") ")
172 | Number_alias (instance,desc) ->
173 sprintf "alias num (instance %d) = \"%s\"." instance desc
175 let pp_associativity = function
176 | Gramext.LeftA -> "left associative"
177 | Gramext.RightA -> "right associative"
178 | Gramext.NonA -> "non associative"
180 let pp_precedence i = sprintf "with precedence %d" i
182 let pp_argument_pattern = function
183 | NotationPt.IdentArg (eta_depth, name) ->
184 let eta_buf = Buffer.create 5 in
185 for i = 1 to eta_depth do
186 Buffer.add_string eta_buf "\\eta."
188 sprintf "%s%s" (Buffer.contents eta_buf) name
190 let pp_interpretation dsc symbol arg_patterns cic_appl_pattern =
191 sprintf "interpretation \"%s\" '%s %s = %s."
193 (String.concat " " (List.map pp_argument_pattern arg_patterns))
194 (NotationPp.pp_cic_appl_pattern cic_appl_pattern)
196 let pp_dir_opt = function
198 | Some `LeftToRight -> "> "
199 | Some `RightToLeft -> "< "
201 let pp_notation status dir_opt l1_pattern assoc prec l2_pattern =
202 sprintf "notation %s\"%s\" %s %s for %s."
204 (pp_l1_pattern status l1_pattern)
205 (pp_associativity assoc)
207 (pp_l2_pattern status l2_pattern)
209 let pp_ncommand status = function
210 | UnificationHint (_,t, n) ->
211 "unification hint " ^ string_of_int n ^ " " ^ NotationPp.pp_term status t
212 | NDiscriminator (_,_)
213 | NInverter (_,_,_,_,_)
214 | NUnivConstraint (_) -> "not supported"
215 | NCoercion (_) -> "not supported"
216 | NObj (_,obj,index) ->
217 (if not index then "-" else "") ^
218 NotationPp.pp_obj (NotationPp.pp_term status) obj
219 | NQed (_,true) -> "qed"
220 | NQed (_,false) -> "qed-"
221 | NCopy (_,name,uri,map) ->
222 "copy " ^ name ^ " from " ^ NUri.string_of_uri uri ^ " with " ^
223 String.concat " and "
225 (fun (a,b) -> NUri.string_of_uri a ^ " ↦ " ^ NUri.string_of_uri b)
227 | Include (_,mode,path) -> (* not precise, since path is absolute *)
228 if mode = WithPreferences then
229 "include \"" ^ path ^ "\""
231 "include' \"" ^ path ^ "\""
232 | Alias (_,s) -> pp_alias s
233 | Interpretation (_, dsc, (symbol, arg_patterns), cic_appl_pattern) ->
234 pp_interpretation dsc symbol arg_patterns cic_appl_pattern
235 | Notation (_, dir_opt, l1_pattern, assoc, prec, l2_pattern) ->
236 pp_notation status dir_opt l1_pattern assoc prec l2_pattern
239 let pp_executable status ~map_unicode_to_tex =
241 | NMacro (_, macro) -> pp_nmacro status macro ^ "."
242 | NTactic (_,tacl) ->
243 String.concat " " (List.map (pp_ntactic status ~map_unicode_to_tex) tacl)
244 | NCommand (_, cmd) -> pp_ncommand status cmd ^ "."
246 let pp_comment status ~map_unicode_to_tex =
248 | Note (_,"") -> Printf.sprintf "\n"
249 | Note (_,str) -> Printf.sprintf "\n(* %s *)" str
251 Printf.sprintf "\n(** %s. **)" (pp_executable status ~map_unicode_to_tex code)
253 let pp_statement status =
255 | Executable (_, ex) -> pp_executable status ex
256 | Comment (_, c) -> pp_comment status c