1 (* Copyright (C) 2000-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/
26 (*CSC codice cut & paste da cicPp e xmlcommand *)
28 exception ImpossiblePossible;;
29 exception NotImplemented;;
31 let dtdname ~ask_dtd_to_the_getter dtd =
32 if ask_dtd_to_the_getter then
33 Helm_registry.get "getter.url" ^ "getdtd?uri=" ^ dtd
35 "http://mowgli.cs.unibo.it/dtd/" ^ dtd
38 let param_attribute_of_params params =
39 String.concat " " (List.map UriManager.string_of_uri params)
42 (*CSC ottimizzazione: al posto di curi cdepth (vedi codice) *)
43 let print_term ~ids_to_inner_sorts =
47 let module U = UriManager in
49 C.ARel (id,idref,n,b) ->
50 let sort = Hashtbl.find ids_to_inner_sorts id in
52 [None,"value",(string_of_int n) ; None,"binder",b ; None,"id",id ;
53 None,"idref",idref ; None,"sort",sort]
54 | C.AVar (id,uri,exp_named_subst) ->
55 let sort = Hashtbl.find ids_to_inner_sorts id in
58 [None,"uri",U.string_of_uri uri;None,"id",id;None,"sort",sort])
61 let sort = Hashtbl.find ids_to_inner_sorts id in
63 [None,"no",(string_of_int n) ; None,"id",id ; None,"sort",sort]
68 [< i ; X.xml_nempty "substitution" [] (aux t') >]
70 [< i ; X.xml_empty "substitution" [] >]
77 | C.Type _ -> "Type" (* TASSI *)
80 X.xml_empty "SORT" [None,"value",(string_of_sort s) ; None,"id",id]
81 | C.AImplicit _ -> raise NotImplemented
82 | C.AProd (last_id,_,_,_) as prods ->
86 let prods,t' = eat_prods t in
90 let prods,t = eat_prods prods in
91 let sort = Hashtbl.find ids_to_inner_sorts last_id in
92 X.xml_nempty "PROD" [None,"type",sort]
94 (fun i (id,binder,s) ->
96 Hashtbl.find ids_to_inner_sorts (Cic2acic.source_id_of_id id)
99 (None,"id",id)::(None,"type",sort)::
102 | C.Name b -> [None,"binder",b]
104 [< i ; X.xml_nempty "decl" attrs (aux s) >]
106 X.xml_nempty "target" [] (aux t)
108 | C.ACast (id,v,t) ->
109 let sort = Hashtbl.find ids_to_inner_sorts id in
110 X.xml_nempty "CAST" [None,"id",id ; None,"sort",sort]
111 [< X.xml_nempty "term" [] (aux v) ;
112 X.xml_nempty "type" [] (aux t)
114 | C.ALambda (last_id,_,_,_) as lambdas ->
115 let rec eat_lambdas =
117 C.ALambda (id,n,s,t) ->
118 let lambdas,t' = eat_lambdas t in
122 let lambdas,t = eat_lambdas lambdas in
123 let sort = Hashtbl.find ids_to_inner_sorts last_id in
124 X.xml_nempty "LAMBDA" [None,"sort",sort]
126 (fun i (id,binder,s) ->
128 Hashtbl.find ids_to_inner_sorts (Cic2acic.source_id_of_id id)
131 (None,"id",id)::(None,"type",sort)::
134 | C.Name b -> [None,"binder",b]
136 [< i ; X.xml_nempty "decl" attrs (aux s) >]
138 X.xml_nempty "target" [] (aux t)
140 | C.ALetIn (xid,C.Anonymous,s,t) ->
142 | C.ALetIn (last_id,C.Name _,_,_) as letins ->
145 C.ALetIn (id,n,s,t) ->
146 let letins,t' = eat_letins t in
150 let letins,t = eat_letins letins in
151 let sort = Hashtbl.find ids_to_inner_sorts last_id in
152 X.xml_nempty "LETIN" [None,"sort",sort]
154 (fun i (id,binder,s) ->
155 let sort = Hashtbl.find ids_to_inner_sorts id in
157 (None,"id",id)::(None,"sort",sort)::
160 | C.Name b -> [None,"binder",b]
162 [< i ; X.xml_nempty "def" attrs (aux s) >]
164 X.xml_nempty "target" [] (aux t)
167 let sort = Hashtbl.find ids_to_inner_sorts id in
168 X.xml_nempty "APPLY" [None,"id",id ; None,"sort",sort]
169 [< (List.fold_right (fun x i -> [< (aux x) ; i >]) li [<>])
171 | C.AConst (id,uri,exp_named_subst) ->
172 let sort = Hashtbl.find ids_to_inner_sorts id in
175 [None,"uri",(U.string_of_uri uri) ; None,"id",id ; None,"sort",sort]
177 | C.AMutInd (id,uri,i,exp_named_subst) ->
179 (X.xml_empty "MUTIND"
180 [None, "uri", (U.string_of_uri uri) ;
181 None, "noType", (string_of_int i) ;
184 | C.AMutConstruct (id,uri,i,j,exp_named_subst) ->
185 let sort = Hashtbl.find ids_to_inner_sorts id in
187 (X.xml_empty "MUTCONSTRUCT"
188 [None,"uri", (U.string_of_uri uri) ;
189 None,"noType",(string_of_int i) ;
190 None,"noConstr",(string_of_int j) ;
191 None,"id",id ; None,"sort",sort]
193 | C.AMutCase (id,uri,typeno,ty,te,patterns) ->
194 let sort = Hashtbl.find ids_to_inner_sorts id in
195 X.xml_nempty "MUTCASE"
196 [None,"uriType",(U.string_of_uri uri) ;
197 None,"noType", (string_of_int typeno) ;
198 None,"id", id ; None,"sort",sort]
199 [< X.xml_nempty "patternsType" [] [< (aux ty) >] ;
200 X.xml_nempty "inductiveTerm" [] [< (aux te) >] ;
202 (fun x i -> [< X.xml_nempty "pattern" [] [< aux x >] ; i>])
205 | C.AFix (id, no, funs) ->
206 let sort = Hashtbl.find ids_to_inner_sorts id in
208 [None,"noFun", (string_of_int no) ; None,"id",id ; None,"sort",sort]
210 (fun (id,fi,ai,ti,bi) i ->
211 [< X.xml_nempty "FixFunction"
212 [None,"id",id ; None,"name", fi ;
213 None,"recIndex", (string_of_int ai)]
214 [< X.xml_nempty "type" [] [< aux ti >] ;
215 X.xml_nempty "body" [] [< aux bi >]
221 | C.ACoFix (id,no,funs) ->
222 let sort = Hashtbl.find ids_to_inner_sorts id in
224 [None,"noFun", (string_of_int no) ; None,"id",id ; None,"sort",sort]
226 (fun (id,fi,ti,bi) i ->
227 [< X.xml_nempty "CofixFunction" [None,"id",id ; None,"name", fi]
228 [< X.xml_nempty "type" [] [< aux ti >] ;
229 X.xml_nempty "body" [] [< aux bi >]
235 and aux_subst buri target subst =
236 (*CSC: I have now no way to assign an ID to the explicit named substitution *)
241 Xml.xml_nempty "instantiate"
242 (match id with None -> [] | Some id -> [None,"id",id])
248 Str.split (Str.regexp "/") (UriManager.string_of_uri buri) in
250 Str.split (Str.regexp "/") (UriManager.string_of_uri uri) in
251 let rec find_relUri buri_frags uri_frags =
252 match buri_frags,uri_frags with
253 [_], _ -> String.concat "/" uri_frags
254 | he1::tl1, he2::tl2 ->
257 | _,_ -> assert false (* uri is not relative to buri *)
259 find_relUri buri_frags uri_frags
261 [< i ; Xml.xml_nempty "arg" [None,"relUri", relUri] (aux arg) >]
268 (* TODO ZACK implement attributes pretty printing *)
269 let xml_of_attrs attributes = [< >]
271 let print_object uri ~ids_to_inner_sorts ~ask_dtd_to_the_getter obj =
272 let module C = Cic in
273 let module X = Xml in
274 let module U = UriManager in
275 let dtdname = dtdname ~ask_dtd_to_the_getter "cic.dtd" in
277 C.ACurrentProof (id,idbody,n,conjectures,bo,ty,params,obj_attrs) ->
278 let params' = param_attribute_of_params params in
279 let xml_attrs = xml_of_attrs obj_attrs in
280 let xml_for_current_proof_body =
281 (*CSC: Should the CurrentProof also have the list of variables it depends on? *)
282 (*CSC: I think so. Not implemented yet. *)
283 X.xml_nempty "CurrentProof"
284 [None,"of",UriManager.string_of_uri uri ; None,"id", id]
287 (fun i (cid,n,canonical_context,t) ->
289 X.xml_nempty "Conjecture"
290 [None,"id",cid ; None,"no",(string_of_int n)]
294 Some (n,C.ADecl t) ->
298 [None,"id",hid;None,"name",n']
299 | C.Anonymous -> [None,"id",hid])
300 (print_term ids_to_inner_sorts t)
301 | Some (n,C.ADef t) ->
305 [None,"id",hid;None,"name",n']
306 | C.Anonymous -> [None,"id",hid])
307 (print_term ids_to_inner_sorts t)
308 | None -> X.xml_empty "Hidden" [None,"id",hid]
312 ) [< >] canonical_context ;
313 X.xml_nempty "Goal" []
314 (print_term ids_to_inner_sorts t)
318 X.xml_nempty "body" [] (print_term ids_to_inner_sorts bo) >]
320 let xml_for_current_proof_type =
321 X.xml_nempty "ConstantType"
322 [None,"name",n ; None,"params",params' ; None,"id", id]
323 (print_term ids_to_inner_sorts ty)
326 [< X.xml_cdata "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n" ;
327 X.xml_cdata ("<!DOCTYPE CurrentProof SYSTEM \""^ dtdname ^ "\">\n");
328 xml_for_current_proof_body
331 [< X.xml_cdata "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n" ;
332 X.xml_cdata ("<!DOCTYPE ConstantType SYSTEM \""^ dtdname ^ "\">\n");
333 xml_for_current_proof_type
337 | C.AConstant (id,idbody,n,bo,ty,params,obj_attrs) ->
338 let params' = param_attribute_of_params params in
339 let xml_attrs = xml_of_attrs obj_attrs in
346 "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n" ;
348 ("<!DOCTYPE ConstantBody SYSTEM \"" ^ dtdname ^ "\">\n") ;
349 X.xml_nempty "ConstantBody"
350 [None,"for",UriManager.string_of_uri uri ;
351 None,"params",params' ; None,"id", id]
352 [< print_term ids_to_inner_sorts bo >]
356 [< X.xml_cdata "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n" ;
357 X.xml_cdata ("<!DOCTYPE ConstantType SYSTEM \""^ dtdname ^ "\">\n");
358 X.xml_nempty "ConstantType"
359 [None,"name",n ; None,"params",params' ; None,"id", id]
360 [< xml_attrs; print_term ids_to_inner_sorts ty >]
364 | C.AVariable (id,n,bo,ty,params,obj_attrs) ->
365 let params' = param_attribute_of_params params in
366 let xml_attrs = xml_of_attrs obj_attrs in
371 X.xml_nempty "body" [] [< print_term ids_to_inner_sorts bo >]
374 [< X.xml_cdata "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n" ;
375 X.xml_cdata ("<!DOCTYPE Variable SYSTEM \"" ^ dtdname ^ "\">\n");
376 X.xml_nempty "Variable"
377 [None,"name",n ; None,"params",params' ; None,"id", id]
379 X.xml_nempty "type" [] (print_term ids_to_inner_sorts ty)
384 | C.AInductiveDefinition (id,tys,params,nparams,obj_attrs) ->
385 let params' = param_attribute_of_params params in
386 let xml_attrs = xml_of_attrs obj_attrs in
387 [< X.xml_cdata "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n" ;
389 ("<!DOCTYPE InductiveDefinition SYSTEM \"" ^ dtdname ^ "\">\n") ;
390 X.xml_nempty "InductiveDefinition"
391 [None,"noParams",string_of_int nparams ;
393 None,"params",params']
396 (fun i (id,typename,finite,arity,cons) ->
398 X.xml_nempty "InductiveType"
399 [None,"id",id ; None,"name",typename ;
400 None,"inductive",(string_of_bool finite)
402 [< X.xml_nempty "arity" []
403 (print_term ids_to_inner_sorts arity) ;
407 X.xml_nempty "Constructor"
409 (print_term ids_to_inner_sorts lc)
421 print_inner_types curi ~ids_to_inner_sorts ~ids_to_inner_types
422 ~ask_dtd_to_the_getter
424 let module C2A = Cic2acic in
425 let module X = Xml in
426 let dtdname = dtdname ~ask_dtd_to_the_getter "cictypes.dtd" in
427 [< X.xml_cdata "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n" ;
429 ("<!DOCTYPE InnerTypes SYSTEM \"" ^ dtdname ^ "\">\n") ;
430 X.xml_nempty "InnerTypes" [None,"of",UriManager.string_of_uri curi]
432 (fun id {C2A.annsynthesized = synty ; C2A.annexpected = expty} x ->
434 X.xml_nempty "TYPE" [None,"of",id]
435 [< X.xml_nempty "synthesized" []
436 [< print_term ids_to_inner_sorts synty >] ;
439 | Some expty' -> X.xml_nempty "expected" [] [< print_term ids_to_inner_sorts expty' >]
442 ) ids_to_inner_types [<>]