1 (* Copyright (C) 2000, 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://cs.unibo.it/helm/.
26 (*CSC codice cut & paste da cicPp e xmlcommand *)
28 exception ImpossiblePossible;;
29 exception NotImplemented;;
31 let param_attribute_of_params params =
32 String.concat " " (List.map UriManager.string_of_uri params)
35 (*CSC ottimizzazione: al posto di curi cdepth (vedi codice) *)
36 let print_term ~ids_to_inner_sorts =
40 let module U = UriManager in
42 C.ARel (id,idref,n,b) ->
43 let sort = Hashtbl.find ids_to_inner_sorts id in
45 ["value",(string_of_int n) ; "binder",b ; "id",id ; "idref",idref ;
47 | C.AVar (id,uri,exp_named_subst) ->
48 let sort = Hashtbl.find ids_to_inner_sorts id in
50 (X.xml_empty "VAR" ["uri",U.string_of_uri uri;"id",id;"sort",sort])
53 let sort = Hashtbl.find ids_to_inner_sorts id in
54 X.xml_nempty "META" ["no",(string_of_int n) ; "id",id ; "sort",sort]
59 [< i ; X.xml_nempty "substitution" [] (aux t') >]
61 [< i ; X.xml_empty "substitution" [] >]
70 X.xml_empty "SORT" ["value",(string_of_sort s) ; "id",id]
71 | C.AImplicit _ -> raise NotImplemented
72 | C.AProd (last_id,_,_,_) as prods ->
76 let prods,t' = eat_prods t in
80 let prods,t = eat_prods prods in
81 let sort = Hashtbl.find ids_to_inner_sorts last_id in
82 X.xml_nempty "PROD" ["type",sort]
84 (fun i (id,binder,s) ->
85 let sort = Hashtbl.find ids_to_inner_sorts id in
87 ("id",id)::("type",sort)::
90 | C.Name b -> ["binder",b]
92 [< i ; X.xml_nempty "decl" attrs (aux s) >]
94 X.xml_nempty "target" [] (aux t)
97 let sort = Hashtbl.find ids_to_inner_sorts id in
98 X.xml_nempty "CAST" ["id",id ; "sort",sort]
99 [< X.xml_nempty "term" [] (aux v) ;
100 X.xml_nempty "type" [] (aux t)
102 | C.ALambda (last_id,_,_,_) as lambdas ->
103 let rec eat_lambdas =
105 C.ALambda (id,n,s,t) ->
106 let lambdas,t' = eat_lambdas t in
110 let lambdas,t = eat_lambdas lambdas in
111 let sort = Hashtbl.find ids_to_inner_sorts last_id in
112 X.xml_nempty "LAMBDA" ["sort",sort]
114 (fun i (id,binder,s) ->
115 let sort = Hashtbl.find ids_to_inner_sorts id in
117 ("id",id)::("type",sort)::
120 | C.Name b -> ["binder",b]
122 [< i ; X.xml_nempty "decl" attrs (aux s) >]
124 X.xml_nempty "target" [] (aux t)
126 | C.ALetIn (xid,C.Anonymous,s,t) ->
128 | C.ALetIn (last_id,C.Name _,_,_) as letins ->
131 C.ALetIn (id,n,s,t) ->
132 let letins,t' = eat_letins t in
136 let letins,t = eat_letins letins in
137 let sort = Hashtbl.find ids_to_inner_sorts last_id in
138 X.xml_nempty "LETIN" ["sort",sort]
140 (fun i (id,binder,s) ->
141 let sort = Hashtbl.find ids_to_inner_sorts id in
143 ("id",id)::("sort",sort)::
146 | C.Name b -> ["binder",b]
148 [< i ; X.xml_nempty "def" attrs (aux s) >]
150 X.xml_nempty "target" [] (aux t)
153 let sort = Hashtbl.find ids_to_inner_sorts id in
154 X.xml_nempty "APPLY" ["id",id ; "sort",sort]
155 [< (List.fold_right (fun x i -> [< (aux x) ; i >]) li [<>])
157 | C.AConst (id,uri,exp_named_subst) ->
158 let sort = Hashtbl.find ids_to_inner_sorts id in
161 ["uri", (U.string_of_uri uri) ; "id",id ; "sort",sort]
163 | C.AMutInd (id,uri,i,exp_named_subst) ->
165 (X.xml_empty "MUTIND"
166 ["uri", (U.string_of_uri uri) ;
167 "noType",(string_of_int i) ;
170 | C.AMutConstruct (id,uri,i,j,exp_named_subst) ->
171 let sort = Hashtbl.find ids_to_inner_sorts id in
173 (X.xml_empty "MUTCONSTRUCT"
174 ["uri", (U.string_of_uri uri) ;
175 "noType",(string_of_int i) ; "noConstr",(string_of_int j) ;
176 "id",id ; "sort",sort]
178 | C.AMutCase (id,uri,typeno,ty,te,patterns) ->
179 let sort = Hashtbl.find ids_to_inner_sorts id in
180 X.xml_nempty "MUTCASE"
181 ["uriType",(U.string_of_uri uri) ;
182 "noType", (string_of_int typeno) ;
183 "id", id ; "sort",sort]
184 [< X.xml_nempty "patternsType" [] [< (aux ty) >] ;
185 X.xml_nempty "inductiveTerm" [] [< (aux te) >] ;
187 (fun x i -> [< X.xml_nempty "pattern" [] [< aux x >] ; i>])
190 | C.AFix (id, no, funs) ->
191 let sort = Hashtbl.find ids_to_inner_sorts id in
193 ["noFun", (string_of_int no) ; "id",id ; "sort",sort]
195 (fun (id,fi,ai,ti,bi) i ->
196 [< X.xml_nempty "FixFunction"
197 ["id",id ; "name", fi ; "recIndex", (string_of_int ai)]
198 [< X.xml_nempty "type" [] [< aux ti >] ;
199 X.xml_nempty "body" [] [< aux bi >]
205 | C.ACoFix (id,no,funs) ->
206 let sort = Hashtbl.find ids_to_inner_sorts id in
208 ["noFun", (string_of_int no) ; "id",id ; "sort",sort]
210 (fun (id,fi,ti,bi) i ->
211 [< X.xml_nempty "CofixFunction" ["id",id ; "name", fi]
212 [< X.xml_nempty "type" [] [< aux ti >] ;
213 X.xml_nempty "body" [] [< aux bi >]
219 and aux_subst buri target subst =
220 (*CSC: I have now no way to assign an ID to the explicit named substitution *)
225 Xml.xml_nempty "instantiate"
226 (match id with None -> [] | Some id -> ["id",id])
232 Str.split (Str.regexp "/") (UriManager.string_of_uri buri) in
234 Str.split (Str.regexp "/") (UriManager.string_of_uri uri) in
235 let rec find_relUri buri_frags uri_frags =
236 match buri_frags,uri_frags with
237 [_], _ -> String.concat "/" uri_frags
238 | he1::tl1, he2::tl2 ->
241 | _,_ -> assert false (* uri is not relative to buri *)
243 find_relUri buri_frags uri_frags
245 [< i ; Xml.xml_nempty "arg" ["relUri", relUri] (aux arg) >]
252 let print_object uri ~ids_to_inner_sorts ~ask_dtd_to_the_getter =
253 let module C = Cic in
254 let module X = Xml in
255 let module U = UriManager in
257 if ask_dtd_to_the_getter then
258 Configuration.getter_url ^ "getdtd?uri=cic.dtd"
260 "http://www.cs.unibo.it/helm/dtd/cic.dtd"
263 C.ACurrentProof (id,idbody,n,conjectures,bo,ty,params) ->
264 let params' = param_attribute_of_params params in
265 let xml_for_current_proof_body =
266 (*CSC: Should the CurrentProof also have the list of variables it depends on? *)
267 (*CSC: I think so. Not implemented yet. *)
268 X.xml_nempty "CurrentProof"
269 ["of",UriManager.string_of_uri uri ; "id", id]
271 (fun i (cid,n,canonical_context,t) ->
273 X.xml_nempty "Conjecture"
274 ["id", cid ; "no",(string_of_int n)]
278 Some (n,C.ADecl t) ->
281 C.Name n' -> ["id",hid;"name",n']
282 | C.Anonymous -> ["id",hid])
283 (print_term ids_to_inner_sorts t)
284 | Some (n,C.ADef t) ->
287 C.Name n' -> ["id",hid;"name",n']
288 | C.Anonymous -> ["id",hid])
289 (print_term ids_to_inner_sorts t)
290 | None -> X.xml_empty "Hidden" ["id",hid]
294 ) [< >] canonical_context ;
295 X.xml_nempty "Goal" []
296 (print_term ids_to_inner_sorts t)
300 X.xml_nempty "body" [] (print_term ids_to_inner_sorts bo) >]
302 let xml_for_current_proof_type =
303 X.xml_nempty "ConstantType" ["name",n ; "params",params' ; "id", id]
304 (print_term ids_to_inner_sorts ty)
307 [< X.xml_cdata "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n" ;
308 X.xml_cdata ("<!DOCTYPE CurrentProof SYSTEM \""^ dtdname ^ "\">\n");
309 xml_for_current_proof_body
312 [< X.xml_cdata "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n" ;
313 X.xml_cdata ("<!DOCTYPE ConstantType SYSTEM \""^ dtdname ^ "\">\n");
314 xml_for_current_proof_type
318 | C.AConstant (id,idbody,n,bo,ty,params) ->
319 let params' = param_attribute_of_params params in
326 "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n" ;
328 ("<!DOCTYPE ConstantBody SYSTEM \"" ^ dtdname ^ "\">\n") ;
329 X.xml_nempty "ConstantBody"
330 ["for",UriManager.string_of_uri uri ; "params",params' ;
332 [< print_term ids_to_inner_sorts bo >]
336 [< X.xml_cdata "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n" ;
337 X.xml_cdata ("<!DOCTYPE ConstantType SYSTEM \""^ dtdname ^ "\">\n");
338 X.xml_nempty "ConstantType"
339 ["name",n ; "params",params' ; "id", id]
340 [< print_term ids_to_inner_sorts ty >]
344 | C.AVariable (id,n,bo,ty,params) ->
345 let params' = param_attribute_of_params params in
350 X.xml_nempty "body" [] [< print_term ids_to_inner_sorts bo >]
353 [< X.xml_cdata "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n" ;
354 X.xml_cdata ("<!DOCTYPE Variable SYSTEM \"" ^ dtdname ^ "\">\n");
355 X.xml_nempty "Variable"
356 ["name",n ; "params",params' ; "id", id]
358 X.xml_nempty "type" [] (print_term ids_to_inner_sorts ty)
363 | C.AInductiveDefinition (id,tys,params,nparams) ->
364 let params' = param_attribute_of_params params in
365 [< X.xml_cdata "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n" ;
367 ("<!DOCTYPE InductiveDefinition SYSTEM \"" ^ dtdname ^ "\">\n") ;
368 X.xml_nempty "InductiveDefinition"
369 ["noParams",string_of_int nparams ;
373 (fun i (id,typename,finite,arity,cons) ->
375 X.xml_nempty "InductiveType"
376 ["id",id ; "name",typename ;
377 "inductive",(string_of_bool finite)
379 [< X.xml_nempty "arity" []
380 (print_term ids_to_inner_sorts arity) ;
384 X.xml_nempty "Constructor"
386 (print_term ids_to_inner_sorts lc)
397 let print_inner_types curi ~ids_to_inner_sorts ~ids_to_inner_types =
398 let module C2A = Cic2acic in
399 let module X = Xml in
400 X.xml_nempty "InnerTypes" ["of",UriManager.string_of_uri curi]
402 (fun id {C2A.annsynthesized = synty ; C2A.annexpected = expty} x ->
404 X.xml_nempty "TYPE" ["of",id]
405 [< print_term ids_to_inner_sorts synty ;
408 | Some expty' -> print_term ids_to_inner_sorts expty'
411 ) ids_to_inner_types [<>]