]> matita.cs.unibo.it Git - helm.git/blob - matita/components/grafite/grafiteAstPp.ml
- Print/Set commands removed
[helm.git] / matita / components / grafite / grafiteAstPp.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 (* $Id$ *)
27
28 open GrafiteAst
29 open Printf
30
31 let tactical_terminator = ""
32 let tactic_terminator = tactical_terminator
33 let command_terminator = tactical_terminator
34
35 let pp_tactic_pattern ~map_unicode_to_tex (what, hyp, goal) = 
36   if what = None && hyp = [] && goal = None then "" else 
37   let what_text =
38     match what with
39     | None -> ""
40     | Some t -> Printf.sprintf "in match (%s) " (NotationPp.pp_term t) in
41   let hyp_text =
42     String.concat " "
43       (List.map (fun (name, p) -> Printf.sprintf "%s:(%s)" name
44        (NotationPp.pp_term p)) hyp) in
45   let goal_text =
46     match goal with
47     | None -> ""
48     | Some t ->
49        let vdash = if map_unicode_to_tex then "\\vdash" else "⊢" in
50         Printf.sprintf "%s (%s)" vdash (NotationPp.pp_term t)
51   in
52    Printf.sprintf "%sin %s%s" what_text hyp_text goal_text
53
54 let rec pp_ntactic ~map_unicode_to_tex =
55  let pp_tactic_pattern = pp_tactic_pattern ~map_unicode_to_tex in
56  function
57   | NApply (_,t) -> "napply " ^ NotationPp.pp_term t
58   | NSmartApply (_,t) -> "fixme"
59   | NAuto (_,(None,flgs)) ->
60       "nautobatch" ^
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 l)) ^
65         String.concat " " (List.map (fun a,b -> a ^ "=" ^ b) flgs)
66   | NCases (_,what,where) -> "ncases " ^ NotationPp.pp_term what ^
67       "...to be implemented..." ^ " " ^ "...to be implemented..."
68   | NConstructor (_,None,l) -> "@ " ^
69       String.concat " " (List.map NotationPp.pp_term l)
70   | NConstructor (_,Some x,l) -> "@" ^ string_of_int x ^ " " ^
71       String.concat " " (List.map NotationPp.pp_term l)
72   | NCase1 (_,n) -> "*" ^ n ^ ":"
73   | NChange (_,what,wwhat) -> "nchange " ^ "...to be implemented..." ^ 
74       " with " ^ NotationPp.pp_term wwhat
75   | NCut (_,t) -> "ncut " ^ NotationPp.pp_term t
76 (*| NDiscriminate (_,t) -> "ndiscriminate " ^ NotationPp.pp_term t
77   | NSubst (_,t) -> "nsubst " ^ NotationPp.pp_term t *)
78   | NDestruct (_,dom,skip) -> "ndestruct ..." 
79   | NElim (_,what,where) -> "nelim " ^ NotationPp.pp_term what ^
80       "...to be implemented..." ^ " " ^ "...to be implemented..."
81   | NId _ -> "nid"
82   | NIntro (_,n) -> "#" ^ n
83   | NIntros (_,l) -> "#" ^ String.concat " " l
84   | NInversion (_,what,where) -> "ninversion " ^ NotationPp.pp_term what ^
85       assert false ^ " " ^ assert false
86   | NLApply (_,t) -> "lapply " ^ NotationPp.pp_term t
87   | NRewrite (_,dir,n,where) -> "nrewrite " ^
88      (match dir with `LeftToRight -> ">" | `RightToLeft -> "<") ^
89      " " ^ NotationPp.pp_term n ^ " " ^ pp_tactic_pattern where
90   | NReduce _ | NGeneralize _ | NLetIn _ | NAssert _ -> "TO BE IMPLEMENTED"
91   | NDot _ -> "."
92   | NSemicolon _ -> ";"
93   | NBranch _ -> "["
94   | NShift _ -> "|"
95   | NPos (_, l) -> String.concat "," (List.map string_of_int l)^ ":"
96   | NPosbyname (_, s) -> s ^ ":"
97   | NWildcard _ -> "*:"
98   | NMerge _ -> "]"
99   | NFocus (_,l) -> 
100       Printf.sprintf "focus %s" 
101         (String.concat " " (List.map string_of_int l))
102   | NUnfocus _ -> "unfocus"
103   | NSkip _ -> "skip"
104   | NTry (_,tac) -> "ntry " ^ pp_ntactic ~map_unicode_to_tex tac
105   | NAssumption _ -> "nassumption"
106   | NBlock (_,l) -> 
107      "(" ^ String.concat " " (List.map (pp_ntactic ~map_unicode_to_tex) l)^ ")"
108   | NRepeat (_,t) -> "nrepeat " ^ pp_ntactic ~map_unicode_to_tex t
109 ;;
110
111 let pp_nmacro = function
112   | NCheck (_, term) -> Printf.sprintf "ncheck %s" (NotationPp.pp_term term)
113   | Screenshot (_, name) -> Printf.sprintf "screenshot \"%s\"" name
114 ;;
115
116 let pp_l1_pattern = NotationPp.pp_term
117 let pp_l2_pattern = NotationPp.pp_term
118
119 let pp_alias = function
120   | Ident_alias (id, uri) -> sprintf "alias id \"%s\" = \"%s\"." id uri
121   | Symbol_alias (symb, instance, desc) ->
122       sprintf "alias symbol \"%s\" %s= \"%s\"."
123         symb
124         (if instance=0 then "" else "(instance "^ string_of_int instance ^ ") ")
125         desc
126   | Number_alias (instance,desc) ->
127       sprintf "alias num (instance %d) = \"%s\"." instance desc
128   
129 let pp_associativity = function
130   | Gramext.LeftA -> "left associative"
131   | Gramext.RightA -> "right associative"
132   | Gramext.NonA -> "non associative"
133
134 let pp_precedence i = sprintf "with precedence %d" i
135
136 let pp_argument_pattern = function
137   | NotationPt.IdentArg (eta_depth, name) ->
138       let eta_buf = Buffer.create 5 in
139       for i = 1 to eta_depth do
140         Buffer.add_string eta_buf "\\eta."
141       done;
142       sprintf "%s%s" (Buffer.contents eta_buf) name
143
144 let pp_interpretation dsc symbol arg_patterns cic_appl_pattern = 
145   sprintf "interpretation \"%s\" '%s %s = %s."
146     dsc symbol
147     (String.concat " " (List.map pp_argument_pattern arg_patterns))
148     (NotationPp.pp_cic_appl_pattern cic_appl_pattern)
149  
150 let pp_dir_opt = function
151   | None -> ""
152   | Some `LeftToRight -> "> "
153   | Some `RightToLeft -> "< "
154
155 let pp_notation dir_opt l1_pattern assoc prec l2_pattern = 
156   sprintf "notation %s\"%s\" %s %s for %s."
157     (pp_dir_opt dir_opt)
158     (pp_l1_pattern l1_pattern)
159     (pp_associativity assoc)
160     (pp_precedence prec)
161     (pp_l2_pattern l2_pattern)
162
163 let pp_ncommand = function
164   | UnificationHint (_,t, n) -> 
165       "unification hint " ^ string_of_int n ^ " " ^ NotationPp.pp_term t
166   | NDiscriminator (_,_)
167   | NInverter (_,_,_,_,_)
168   | NUnivConstraint (_) -> "not supported"
169   | NCoercion (_) -> "not supported"
170   | NObj (_,obj) -> NotationPp.pp_obj NotationPp.pp_term obj
171   | NQed (_) -> "nqed"
172   | NCopy (_,name,uri,map) -> 
173       "copy " ^ name ^ " from " ^ NUri.string_of_uri uri ^ " with " ^ 
174         String.concat " and " 
175           (List.map 
176             (fun (a,b) -> NUri.string_of_uri a ^ " ↦ " ^ NUri.string_of_uri b) 
177             map)
178   | Include (_,mode,path) -> (* not precise, since path is absolute *)
179       if mode = WithPreferences then
180         "include \"" ^ path ^ "\"."
181       else
182         "include' \"" ^ path ^ "\"."
183   | Alias (_,s) -> pp_alias s
184   | Interpretation (_, dsc, (symbol, arg_patterns), cic_appl_pattern) ->
185       pp_interpretation dsc symbol arg_patterns cic_appl_pattern
186   | Notation (_, dir_opt, l1_pattern, assoc, prec, l2_pattern) ->
187       pp_notation dir_opt l1_pattern assoc prec l2_pattern
188 ;;
189     
190 let pp_executable ~map_unicode_to_tex =
191   function
192   | NMacro (_, macro) -> pp_nmacro macro ^ "."
193   | NTactic (_,tacl) ->
194       String.concat " " (List.map (pp_ntactic ~map_unicode_to_tex) tacl)
195   | NCommand (_, cmd) -> pp_ncommand cmd ^ "."
196                       
197 let pp_comment ~map_unicode_to_tex =
198   function
199   | Note (_,"") -> Printf.sprintf "\n"
200   | Note (_,str) -> Printf.sprintf "\n(* %s *)" str
201   | Code (_,code) ->
202       Printf.sprintf "\n(** %s. **)" (pp_executable ~map_unicode_to_tex code)
203
204 let pp_statement =
205   function
206   | Executable (_, ex) -> pp_executable ex 
207   | Comment (_, c) -> pp_comment c