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 NotImplemented;;
30 let dtdname ~ask_dtd_to_the_getter dtd =
31 if ask_dtd_to_the_getter then
32 Helm_registry.get "getter.url" ^ "getdtd?uri=" ^ dtd
34 "http://mowgli.cs.unibo.it/dtd/" ^ dtd
37 let param_attribute_of_params params =
38 String.concat " " (List.map UriManager.string_of_uri params)
41 (*CSC ottimizzazione: al posto di curi cdepth (vedi codice) *)
42 let print_term ~ids_to_inner_sorts =
44 Cic2acic.string_of_sort (Hashtbl.find ids_to_inner_sorts id)
49 let module U = UriManager in
51 C.ARel (id,idref,n,b) ->
52 let sort = find_sort id in
54 [None,"value",(string_of_int n) ; None,"binder",b ; None,"id",id ;
55 None,"idref",idref ; None,"sort",sort]
56 | C.AVar (id,uri,exp_named_subst) ->
57 let sort = find_sort id in
60 [None,"uri",U.string_of_uri uri;None,"id",id;None,"sort",sort])
63 let sort = find_sort id in
65 [None,"no",(string_of_int n) ; None,"id",id ; None,"sort",sort]
70 [< i ; X.xml_nempty "substitution" [] (aux t') >]
72 [< i ; X.xml_empty "substitution" [] >]
75 let string_of_sort s =
76 Cic2acic.string_of_sort (Cic2acic.sort_of_sort s)
78 X.xml_empty "SORT" [None,"value",(string_of_sort s) ; None,"id",id]
79 | C.AImplicit _ -> raise NotImplemented
80 | C.AProd (last_id,_,_,_) as prods ->
84 let prods,t' = eat_prods t in
88 let prods,t = eat_prods prods in
89 let sort = find_sort last_id in
90 X.xml_nempty "PROD" [None,"type",sort]
92 (fun i (id,binder,s) ->
93 let sort = find_sort (Cic2acic.source_id_of_id id) in
95 (None,"id",id)::(None,"type",sort)::
98 | C.Name b -> [None,"binder",b]
100 [< i ; X.xml_nempty "decl" attrs (aux s) >]
102 X.xml_nempty "target" [] (aux t)
104 | C.ACast (id,v,t) ->
105 let sort = find_sort id in
106 X.xml_nempty "CAST" [None,"id",id ; None,"sort",sort]
107 [< X.xml_nempty "term" [] (aux v) ;
108 X.xml_nempty "type" [] (aux t)
110 | C.ALambda (last_id,_,_,_) as lambdas ->
111 let rec eat_lambdas =
113 C.ALambda (id,n,s,t) ->
114 let lambdas,t' = eat_lambdas t in
118 let lambdas,t = eat_lambdas lambdas in
119 let sort = find_sort last_id in
120 X.xml_nempty "LAMBDA" [None,"sort",sort]
122 (fun i (id,binder,s) ->
123 let sort = find_sort (Cic2acic.source_id_of_id id) in
125 (None,"id",id)::(None,"type",sort)::
128 | C.Name b -> [None,"binder",b]
130 [< i ; X.xml_nempty "decl" attrs (aux s) >]
132 X.xml_nempty "target" [] (aux t)
134 | C.ALetIn (xid,C.Anonymous,s,t) ->
136 | C.ALetIn (last_id,C.Name _,_,_) as letins ->
139 C.ALetIn (id,n,s,t) ->
140 let letins,t' = eat_letins t in
144 let letins,t = eat_letins letins in
145 let sort = find_sort last_id in
146 X.xml_nempty "LETIN" [None,"sort",sort]
148 (fun i (id,binder,s) ->
149 let sort = find_sort id in
151 (None,"id",id)::(None,"sort",sort)::
154 | C.Name b -> [None,"binder",b]
156 [< i ; X.xml_nempty "def" attrs (aux s) >]
158 X.xml_nempty "target" [] (aux t)
161 let sort = find_sort id in
162 X.xml_nempty "APPLY" [None,"id",id ; None,"sort",sort]
163 [< (List.fold_right (fun x i -> [< (aux x) ; i >]) li [<>])
165 | C.AConst (id,uri,exp_named_subst) ->
166 let sort = find_sort id in
169 [None,"uri",(U.string_of_uri uri) ; None,"id",id ; None,"sort",sort]
171 | C.AMutInd (id,uri,i,exp_named_subst) ->
173 (X.xml_empty "MUTIND"
174 [None, "uri", (U.string_of_uri uri) ;
175 None, "noType", (string_of_int i) ;
178 | C.AMutConstruct (id,uri,i,j,exp_named_subst) ->
179 let sort = find_sort id in
181 (X.xml_empty "MUTCONSTRUCT"
182 [None,"uri", (U.string_of_uri uri) ;
183 None,"noType",(string_of_int i) ;
184 None,"noConstr",(string_of_int j) ;
185 None,"id",id ; None,"sort",sort]
187 | C.AMutCase (id,uri,typeno,ty,te,patterns) ->
188 let sort = find_sort id in
189 X.xml_nempty "MUTCASE"
190 [None,"uriType",(U.string_of_uri uri) ;
191 None,"noType", (string_of_int typeno) ;
192 None,"id", id ; None,"sort",sort]
193 [< X.xml_nempty "patternsType" [] [< (aux ty) >] ;
194 X.xml_nempty "inductiveTerm" [] [< (aux te) >] ;
196 (fun x i -> [< X.xml_nempty "pattern" [] [< aux x >] ; i>])
199 | C.AFix (id, no, funs) ->
200 let sort = find_sort id in
202 [None,"noFun", (string_of_int no) ; None,"id",id ; None,"sort",sort]
204 (fun (id,fi,ai,ti,bi) i ->
205 [< X.xml_nempty "FixFunction"
206 [None,"id",id ; None,"name", fi ;
207 None,"recIndex", (string_of_int ai)]
208 [< X.xml_nempty "type" [] [< aux ti >] ;
209 X.xml_nempty "body" [] [< aux bi >]
215 | C.ACoFix (id,no,funs) ->
216 let sort = find_sort id in
218 [None,"noFun", (string_of_int no) ; None,"id",id ; None,"sort",sort]
220 (fun (id,fi,ti,bi) i ->
221 [< X.xml_nempty "CofixFunction" [None,"id",id ; None,"name", fi]
222 [< X.xml_nempty "type" [] [< aux ti >] ;
223 X.xml_nempty "body" [] [< aux bi >]
229 and aux_subst buri target subst =
230 (*CSC: I have now no way to assign an ID to the explicit named substitution *)
235 Xml.xml_nempty "instantiate"
236 (match id with None -> [] | Some id -> [None,"id",id])
242 Str.split (Str.regexp "/") (UriManager.string_of_uri buri) in
244 Str.split (Str.regexp "/") (UriManager.string_of_uri uri) in
245 let rec find_relUri buri_frags uri_frags =
246 match buri_frags,uri_frags with
247 [_], _ -> String.concat "/" uri_frags
248 | he1::tl1, he2::tl2 ->
251 | _,_ -> assert false (* uri is not relative to buri *)
253 find_relUri buri_frags uri_frags
255 [< i ; Xml.xml_nempty "arg" [None,"relUri", relUri] (aux arg) >]
262 let xml_of_attrs attributes =
263 let class_of = function
264 | `Coercion -> Xml.xml_empty "class" [None,"value","coercion"]
266 Xml.xml_nempty "class" [None,"value","elim"]
268 "SORT" [None,"value",
269 (Cic2acic.string_of_sort (Cic2acic.sort_of_sort s)) ;
270 None,"id","elimination_sort"] >]
271 | `Record field_names ->
272 Xml.xml_nempty "class" [None,"value","record"]
275 [< Xml.xml_empty "field" [None,"name",name]; res >]
277 | `Projection -> Xml.xml_empty "class" [None,"value","projection"]
279 let flavour_of = function
280 | `Definition -> Xml.xml_empty "flavour" [None, "value", "definition"]
281 | `Fact -> Xml.xml_empty "flavour" [None, "value", "fact"]
282 | `Lemma -> Xml.xml_empty "flavour" [None, "value", "lemma"]
283 | `Remark -> Xml.xml_empty "flavour" [None, "value", "remark"]
284 | `Theorem -> Xml.xml_empty "flavour" [None, "value", "theorem"]
285 | `Variant -> Xml.xml_empty "flavour" [None, "value", "variant"]
287 let xml_attr_of = function
288 | `Generated -> Xml.xml_empty "generated" []
289 | `Class c -> class_of c
290 | `Flavour f -> flavour_of f
294 (fun attr res -> [< xml_attr_of attr ; res >]) attributes [<>]
296 Xml.xml_nempty "attributes" [] xml_attrs
298 let print_object uri ~ids_to_inner_sorts ~ask_dtd_to_the_getter obj =
300 Cic2acic.string_of_sort (Hashtbl.find ids_to_inner_sorts id)
302 let module C = Cic in
303 let module X = Xml in
304 let module U = UriManager in
305 let dtdname = dtdname ~ask_dtd_to_the_getter "cic.dtd" in
307 C.ACurrentProof (id,idbody,n,conjectures,bo,ty,params,obj_attrs) ->
308 let params' = param_attribute_of_params params in
309 let xml_attrs = xml_of_attrs obj_attrs in
310 let xml_for_current_proof_body =
311 (*CSC: Should the CurrentProof also have the list of variables it depends on? *)
312 (*CSC: I think so. Not implemented yet. *)
313 X.xml_nempty "CurrentProof"
314 [None,"of",UriManager.string_of_uri uri ; None,"id", id]
317 (fun i (cid,n,canonical_context,t) ->
319 X.xml_nempty "Conjecture"
320 [None,"id",cid ; None,"no",(string_of_int n)]
324 Some (n,C.ADecl t) ->
328 [None,"id",hid;None,"name",n']
329 | C.Anonymous -> [None,"id",hid])
330 (print_term ids_to_inner_sorts t)
331 | Some (n,C.ADef t) ->
335 [None,"id",hid;None,"name",n']
336 | C.Anonymous -> [None,"id",hid])
337 (print_term ids_to_inner_sorts t)
338 | None -> X.xml_empty "Hidden" [None,"id",hid]
342 ) [< >] canonical_context ;
343 X.xml_nempty "Goal" []
344 (print_term ids_to_inner_sorts t)
348 X.xml_nempty "body" [] (print_term ids_to_inner_sorts bo) >]
350 let xml_for_current_proof_type =
351 X.xml_nempty "ConstantType"
352 [None,"name",n ; None,"params",params' ; None,"id", id]
353 (print_term ids_to_inner_sorts ty)
356 [< X.xml_cdata "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n" ;
357 X.xml_cdata ("<!DOCTYPE CurrentProof SYSTEM \""^ dtdname ^ "\">\n");
358 xml_for_current_proof_body
361 [< X.xml_cdata "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n" ;
362 X.xml_cdata ("<!DOCTYPE ConstantType SYSTEM \""^ dtdname ^ "\">\n");
363 xml_for_current_proof_type
367 | C.AConstant (id,idbody,n,bo,ty,params,obj_attrs) ->
368 let params' = param_attribute_of_params params in
369 let xml_attrs = xml_of_attrs obj_attrs in
376 "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n" ;
378 ("<!DOCTYPE ConstantBody SYSTEM \"" ^ dtdname ^ "\">\n") ;
379 X.xml_nempty "ConstantBody"
380 [None,"for",UriManager.string_of_uri uri ;
381 None,"params",params' ; None,"id", id]
382 [< print_term ids_to_inner_sorts bo >]
386 [< X.xml_cdata "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n" ;
387 X.xml_cdata ("<!DOCTYPE ConstantType SYSTEM \""^ dtdname ^ "\">\n");
388 X.xml_nempty "ConstantType"
389 [None,"name",n ; None,"params",params' ; None,"id", id]
390 [< xml_attrs; print_term ids_to_inner_sorts ty >]
394 | C.AVariable (id,n,bo,ty,params,obj_attrs) ->
395 let params' = param_attribute_of_params params in
396 let xml_attrs = xml_of_attrs obj_attrs in
401 X.xml_nempty "body" [] [< print_term ids_to_inner_sorts bo >]
404 [< X.xml_cdata "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n" ;
405 X.xml_cdata ("<!DOCTYPE Variable SYSTEM \"" ^ dtdname ^ "\">\n");
406 X.xml_nempty "Variable"
407 [None,"name",n ; None,"params",params' ; None,"id", id]
409 X.xml_nempty "type" [] (print_term ids_to_inner_sorts ty)
414 | C.AInductiveDefinition (id,tys,params,nparams,obj_attrs) ->
415 let params' = param_attribute_of_params params in
416 let xml_attrs = xml_of_attrs obj_attrs in
417 [< X.xml_cdata "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n" ;
419 ("<!DOCTYPE InductiveDefinition SYSTEM \"" ^ dtdname ^ "\">\n") ;
420 X.xml_nempty "InductiveDefinition"
421 [None,"noParams",string_of_int nparams ;
423 None,"params",params']
426 (fun i (id,typename,finite,arity,cons) ->
428 X.xml_nempty "InductiveType"
429 [None,"id",id ; None,"name",typename ;
430 None,"inductive",(string_of_bool finite)
432 [< X.xml_nempty "arity" []
433 (print_term ids_to_inner_sorts arity) ;
437 X.xml_nempty "Constructor"
439 (print_term ids_to_inner_sorts lc)
451 print_inner_types curi ~ids_to_inner_sorts ~ids_to_inner_types
452 ~ask_dtd_to_the_getter
454 let module C2A = Cic2acic in
455 let module X = Xml in
456 let dtdname = dtdname ~ask_dtd_to_the_getter "cictypes.dtd" in
457 [< X.xml_cdata "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n" ;
459 ("<!DOCTYPE InnerTypes SYSTEM \"" ^ dtdname ^ "\">\n") ;
460 X.xml_nempty "InnerTypes" [None,"of",UriManager.string_of_uri curi]
462 (fun id {C2A.annsynthesized = synty ; C2A.annexpected = expty} x ->
464 X.xml_nempty "TYPE" [None,"of",id]
465 [< X.xml_nempty "synthesized" []
466 [< print_term ids_to_inner_sorts synty >] ;
469 | Some expty' -> X.xml_nempty "expected" []
470 [< print_term ids_to_inner_sorts expty' >]
473 ) ids_to_inner_types [<>]