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 rec pp_ntactic status ~map_unicode_to_tex =
55 let pp_tactic_pattern = pp_tactic_pattern ~map_unicode_to_tex in
57 | NApply (_,t) -> "@" ^ NotationPp.pp_term status t
58 | NSmartApply (_,t) -> "fixme"
59 | NAuto (_,(None,flgs)) ->
61 String.concat " " (List.map (fun a,b -> a ^ "=" ^ b) flgs)
62 | NAuto (_,(Some (_,l),flgs)) ->
63 "nautobatch" ^ " by " ^
64 (String.concat "," (List.map (NotationPp.pp_term status) l)) ^
65 String.concat " " (List.map (fun a,b -> a ^ "=" ^ b) flgs)
66 | NCases (_,what,where) -> "ncases " ^ NotationPp.pp_term status what ^
67 "...to be implemented..." ^ " " ^ "...to be implemented..."
68 | NConstructor (_,None,l) -> "@ " ^
69 String.concat " " (List.map (NotationPp.pp_term status) l)
70 | NConstructor (_,Some x,l) -> "@" ^ string_of_int x ^ " " ^
71 String.concat " " (List.map (NotationPp.pp_term status) l)
72 | NCase1 (_,n) -> "*" ^ n ^ ":"
73 | NChange (_,what,wwhat) -> "nchange " ^ "...to be implemented..." ^
74 " with " ^ NotationPp.pp_term status wwhat
75 | NCut (_,t) -> "ncut " ^ NotationPp.pp_term status t
76 (*| NDiscriminate (_,t) -> "ndiscriminate " ^ NotationPp.pp_term status t
77 | NSubst (_,t) -> "nsubst " ^ NotationPp.pp_term status t *)
78 | NClear (_,l) -> "nclear " ^ String.concat " " l
79 | NDestruct (_,dom,skip) -> "ndestruct ..."
80 | NElim (_,what,where) -> "nelim " ^ NotationPp.pp_term status what ^
81 "...to be implemented..." ^ " " ^ "...to be implemented..."
83 | NIntro (_,n) -> "#" ^ n
84 | NIntros (_,l) -> "#" ^ String.concat " " l
85 | NInversion (_,what,where) -> "ninversion " ^ NotationPp.pp_term status what ^
86 assert false ^ " " ^ assert false
87 | NLApply (_,t) -> "lapply " ^ NotationPp.pp_term status t
88 | NRewrite (_,dir,n,where) -> "nrewrite " ^
89 (match dir with `LeftToRight -> ">" | `RightToLeft -> "<") ^
90 " " ^ NotationPp.pp_term status n ^ " " ^ pp_tactic_pattern status where
91 | NReduce _ | NGeneralize _ | NLetIn _ | NAssert _ -> "TO BE IMPLEMENTED"
96 | NPos (_, l) -> String.concat "," (List.map string_of_int l)^ ":"
97 | NPosbyname (_, s) -> s ^ ":"
101 Printf.sprintf "focus %s"
102 (String.concat " " (List.map string_of_int l))
103 | NUnfocus _ -> "unfocus"
105 | NTry (_,tac) -> "ntry " ^ pp_ntactic status ~map_unicode_to_tex tac
106 | NAssumption _ -> "nassumption"
108 "(" ^ String.concat " " (List.map (pp_ntactic status ~map_unicode_to_tex) l)^ ")"
109 | NRepeat (_,t) -> "nrepeat " ^ pp_ntactic status ~map_unicode_to_tex t
112 let pp_nmacro status = function
113 | NCheck (_, term) -> Printf.sprintf "ncheck %s" (NotationPp.pp_term status term)
114 | Screenshot (_, name) -> Printf.sprintf "screenshot \"%s\"" name
117 let pp_l1_pattern = NotationPp.pp_term
118 let pp_l2_pattern = NotationPp.pp_term
120 let pp_alias = function
121 | Ident_alias (id, uri) -> sprintf "alias id \"%s\" = \"%s\"." id uri
122 | Symbol_alias (symb, (* uri *) _, desc) ->
123 sprintf "alias symbol \"%s\" = \"%s\"."
125 | Number_alias ((* uri *) _,desc) ->
126 sprintf "alias num = \"%s\"." desc
128 let pp_associativity = function
129 | Gramext.LeftA -> "left associative"
130 | Gramext.RightA -> "right associative"
131 | Gramext.NonA -> "non associative"
133 let pp_precedence i = sprintf "with precedence %d" i
135 let pp_argument_pattern = function
136 | NotationPt.IdentArg (eta_depth, name) ->
137 let eta_buf = Buffer.create 5 in
138 for i = 1 to eta_depth do
139 Buffer.add_string eta_buf "\\eta."
141 sprintf "%s%s" (Buffer.contents eta_buf) name
143 let pp_interpretation dsc symbol arg_patterns cic_appl_pattern =
144 sprintf "interpretation \"%s\" '%s %s = %s."
146 (String.concat " " (List.map pp_argument_pattern arg_patterns))
147 (NotationPp.pp_cic_appl_pattern cic_appl_pattern)
149 let pp_dir_opt = function
151 | Some `LeftToRight -> "> "
152 | Some `RightToLeft -> "< "
154 let pp_notation status dir_opt l1_pattern assoc prec l2_pattern =
155 sprintf "notation %s\"%s\" %s %s for %s."
157 (pp_l1_pattern status l1_pattern)
158 (pp_associativity assoc)
160 (pp_l2_pattern status l2_pattern)
162 let pp_ncommand status = function
163 | UnificationHint (_,t, n) ->
164 "unification hint " ^ string_of_int n ^ " " ^ NotationPp.pp_term status t
165 | NDiscriminator (_,_)
166 | NInverter (_,_,_,_,_)
167 | NUnivConstraint (_) -> "not supported"
168 | NCoercion (_) -> "not supported"
169 | NObj (_,obj,index) ->
170 (if not index then "-" else "") ^
171 NotationPp.pp_obj (NotationPp.pp_term status) obj
172 | NQed (_,true) -> "qed"
173 | NQed (_,false) -> "qed-"
174 | NCopy (_,name,uri,map) ->
175 "copy " ^ name ^ " from " ^ NUri.string_of_uri uri ^ " with " ^
176 String.concat " and "
178 (fun (a,b) -> NUri.string_of_uri a ^ " ↦ " ^ NUri.string_of_uri b)
180 | Include (_,mode,path) -> (* not precise, since path is absolute *)
181 if mode = WithPreferences then
182 "include \"" ^ path ^ "\""
184 "include' \"" ^ path ^ "\""
185 | Alias (_,s) -> pp_alias s
186 | Interpretation (_, dsc, (symbol, arg_patterns), cic_appl_pattern) ->
187 pp_interpretation dsc symbol arg_patterns cic_appl_pattern
188 | Notation (_, dir_opt, l1_pattern, assoc, prec, l2_pattern) ->
189 pp_notation status dir_opt l1_pattern assoc prec l2_pattern
192 let pp_executable status ~map_unicode_to_tex =
194 | NMacro (_, macro) -> pp_nmacro status macro ^ "."
195 | NTactic (_,tacl) ->
196 String.concat " " (List.map (pp_ntactic status ~map_unicode_to_tex) tacl)
197 | NCommand (_, cmd) -> pp_ncommand status cmd ^ "."
199 let pp_comment status ~map_unicode_to_tex =
201 | Note (_,"") -> Printf.sprintf "\n"
202 | Note (_,str) -> Printf.sprintf "\n(* %s *)" str
204 Printf.sprintf "\n(** %s. **)" (pp_executable status ~map_unicode_to_tex code)
206 let pp_statement status =
208 | Executable (_, ex) -> pp_executable status ex
209 | Comment (_, c) -> pp_comment status c