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/
28 (*CSC codice cut & paste da cicPp e xmlcommand *)
30 exception NotImplemented;;
32 let dtdname ~ask_dtd_to_the_getter dtd =
33 if ask_dtd_to_the_getter then
34 Helm_registry.get "getter.url" ^ "getdtd?uri=" ^ dtd
36 "http://mowgli.cs.unibo.it/dtd/" ^ dtd
39 let param_attribute_of_params params =
40 String.concat " " (List.map UriManager.string_of_uri params)
43 (*CSC ottimizzazione: al posto di curi cdepth (vedi codice) *)
44 let print_term ?ids_to_inner_sorts =
45 let find_sort name id =
46 match ids_to_inner_sorts with
48 | Some ids_to_inner_sorts ->
49 [None,name,Cic2acic.string_of_sort (Hashtbl.find ids_to_inner_sorts id)]
54 let module U = UriManager in
56 C.ARel (id,idref,n,b) ->
57 let sort = find_sort "sort" id in
60 [None,"value",(string_of_int n) ; None,"binder",b ; None,"id",id ;
62 | C.AVar (id,uri,exp_named_subst) ->
63 let sort = find_sort "sort" id in
66 (sort @ [None,"uri",U.string_of_uri uri;None,"id",id]))
69 let sort = find_sort "sort" id in
71 (sort @ [None,"no",(string_of_int n) ; None,"id",id])
76 [< i ; X.xml_nempty "substitution" [] (aux t') >]
78 [< i ; X.xml_empty "substitution" [] >]
81 let string_of_sort s =
82 Cic2acic.string_of_sort (Cic2acic.sort_of_sort s)
84 X.xml_empty "SORT" [None,"value",(string_of_sort s) ; None,"id",id]
85 | C.AImplicit _ -> raise NotImplemented
86 | C.AProd (last_id,_,_,_) as prods ->
90 let prods,t' = eat_prods t in
94 let prods,t = eat_prods prods in
95 let sort = find_sort "type" last_id in
96 X.xml_nempty "PROD" sort
98 (fun i (id,binder,s) ->
99 let sort = find_sort "type" (Cic2acic.source_id_of_id id) in
101 sort @ ((None,"id",id)::
104 | C.Name b -> [None,"binder",b])
106 [< i ; X.xml_nempty "decl" attrs (aux s) >]
108 X.xml_nempty "target" [] (aux t)
110 | C.ACast (id,v,t) ->
111 let sort = find_sort "sort" id in
112 X.xml_nempty "CAST" (sort @ [None,"id",id])
113 [< X.xml_nempty "term" [] (aux v) ;
114 X.xml_nempty "type" [] (aux t)
116 | C.ALambda (last_id,_,_,_) as lambdas ->
117 let rec eat_lambdas =
119 C.ALambda (id,n,s,t) ->
120 let lambdas,t' = eat_lambdas t in
124 let lambdas,t = eat_lambdas lambdas in
125 let sort = find_sort "sort" last_id in
126 X.xml_nempty "LAMBDA" sort
128 (fun i (id,binder,s) ->
129 let sort = find_sort "type" (Cic2acic.source_id_of_id id) in
131 sort @ ((None,"id",id)::
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 = find_sort "sort" last_id in
152 X.xml_nempty "LETIN" sort
154 (fun i (id,binder,s) ->
155 let sort = find_sort "sort" id in
157 sort @ ((None,"id",id)::
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 = find_sort "sort" id in
168 X.xml_nempty "APPLY" (sort @ [None,"id",id])
169 [< (List.fold_right (fun x i -> [< (aux x) ; i >]) li [<>])
171 | C.AConst (id,uri,exp_named_subst) ->
172 let sort = find_sort "sort" id in
175 (sort @ [None,"uri",(U.string_of_uri uri) ; None,"id",id])
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 = find_sort "sort" id in
187 (X.xml_empty "MUTCONSTRUCT"
189 [None,"uri", (U.string_of_uri uri) ;
190 None,"noType",(string_of_int i) ;
191 None,"noConstr",(string_of_int j) ;
194 | C.AMutCase (id,uri,typeno,ty,te,patterns) ->
195 let sort = find_sort "sort" id in
196 X.xml_nempty "MUTCASE"
198 [None,"uriType",(U.string_of_uri uri) ;
199 None,"noType", (string_of_int typeno) ;
201 [< X.xml_nempty "patternsType" [] [< (aux ty) >] ;
202 X.xml_nempty "inductiveTerm" [] [< (aux te) >] ;
204 (fun x i -> [< X.xml_nempty "pattern" [] [< aux x >] ; i>])
207 | C.AFix (id, no, funs) ->
208 let sort = find_sort "sort" id in
210 (sort @ [None,"noFun", (string_of_int no) ; None,"id",id])
212 (fun (id,fi,ai,ti,bi) i ->
213 [< X.xml_nempty "FixFunction"
214 [None,"id",id ; None,"name", fi ;
215 None,"recIndex", (string_of_int ai)]
216 [< X.xml_nempty "type" [] [< aux ti >] ;
217 X.xml_nempty "body" [] [< aux bi >]
223 | C.ACoFix (id,no,funs) ->
224 let sort = find_sort "sort" id in
226 (sort @ [None,"noFun", (string_of_int no) ; None,"id",id])
228 (fun (id,fi,ti,bi) i ->
229 [< X.xml_nempty "CofixFunction" [None,"id",id ; None,"name", fi]
230 [< X.xml_nempty "type" [] [< aux ti >] ;
231 X.xml_nempty "body" [] [< aux bi >]
237 and aux_subst buri target subst =
238 (*CSC: I have now no way to assign an ID to the explicit named substitution *)
243 Xml.xml_nempty "instantiate"
244 (match id with None -> [] | Some id -> [None,"id",id])
250 Str.split (Str.regexp "/") (UriManager.string_of_uri buri) in
252 Str.split (Str.regexp "/") (UriManager.string_of_uri uri) in
253 let rec find_relUri buri_frags uri_frags =
254 match buri_frags,uri_frags with
255 [_], _ -> String.concat "/" uri_frags
256 | he1::tl1, he2::tl2 ->
259 | _,_ -> assert false (* uri is not relative to buri *)
261 find_relUri buri_frags uri_frags
263 [< i ; Xml.xml_nempty "arg" [None,"relUri", relUri] (aux arg) >]
270 let xml_of_attrs attributes =
271 let class_of = function
273 Xml.xml_empty "class" [None,"value","coercion";None,"arity",string_of_int n]
275 Xml.xml_nempty "class" [None,"value","elim"]
277 "SORT" [None,"value",
278 (Cic2acic.string_of_sort (Cic2acic.sort_of_sort s)) ;
279 None,"id","elimination_sort"] >]
280 | `Record field_names ->
281 Xml.xml_nempty "class" [None,"value","record"]
283 (fun (name,coercion,arity) res ->
284 [< Xml.xml_empty "field"
287 name ^ " coercion " ^ string_of_int arity
292 | `Projection -> Xml.xml_empty "class" [None,"value","projection"]
294 let flavour_of = function
295 | `Definition -> Xml.xml_empty "flavour" [None, "value", "definition"]
296 | `Fact -> Xml.xml_empty "flavour" [None, "value", "fact"]
297 | `Lemma -> Xml.xml_empty "flavour" [None, "value", "lemma"]
298 | `Remark -> Xml.xml_empty "flavour" [None, "value", "remark"]
299 | `Theorem -> Xml.xml_empty "flavour" [None, "value", "theorem"]
300 | `Variant -> Xml.xml_empty "flavour" [None, "value", "variant"]
301 | `Axiom -> Xml.xml_empty "flavour" [None, "value", "axiom"]
303 let xml_attr_of = function
304 | `Generated -> Xml.xml_empty "generated" []
305 | `Class c -> class_of c
306 | `Flavour f -> flavour_of f
310 (fun attr res -> [< xml_attr_of attr ; res >]) attributes [<>]
312 Xml.xml_nempty "attributes" [] xml_attrs
314 let print_object uri ?ids_to_inner_sorts ~ask_dtd_to_the_getter obj =
315 let module C = Cic in
316 let module X = Xml in
317 let module U = UriManager in
318 let dtdname = dtdname ~ask_dtd_to_the_getter "cic.dtd" in
320 C.ACurrentProof (id,idbody,n,conjectures,bo,ty,params,obj_attrs) ->
321 let params' = param_attribute_of_params params in
322 let xml_attrs = xml_of_attrs obj_attrs in
323 let xml_for_current_proof_body =
324 (*CSC: Should the CurrentProof also have the list of variables it depends on? *)
325 (*CSC: I think so. Not implemented yet. *)
326 X.xml_nempty "CurrentProof"
327 [None,"of",UriManager.string_of_uri uri ; None,"id", id]
330 (fun i (cid,n,canonical_context,t) ->
332 X.xml_nempty "Conjecture"
333 [None,"id",cid ; None,"no",(string_of_int n)]
337 Some (n,C.ADecl t) ->
341 [None,"id",hid;None,"name",n']
342 | C.Anonymous -> [None,"id",hid])
343 (print_term ?ids_to_inner_sorts t)
344 | Some (n,C.ADef t) ->
348 [None,"id",hid;None,"name",n']
349 | C.Anonymous -> [None,"id",hid])
350 (print_term ?ids_to_inner_sorts t)
351 | None -> X.xml_empty "Hidden" [None,"id",hid]
355 ) [< >] canonical_context ;
356 X.xml_nempty "Goal" []
357 (print_term ?ids_to_inner_sorts t)
361 X.xml_nempty "body" [] (print_term ?ids_to_inner_sorts bo) >]
363 let xml_for_current_proof_type =
364 X.xml_nempty "ConstantType"
365 [None,"name",n ; None,"params",params' ; None,"id", id]
366 (print_term ?ids_to_inner_sorts ty)
369 [< X.xml_cdata "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n" ;
370 X.xml_cdata ("<!DOCTYPE CurrentProof SYSTEM \""^ dtdname ^ "\">\n");
371 xml_for_current_proof_body
374 [< X.xml_cdata "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n" ;
375 X.xml_cdata ("<!DOCTYPE ConstantType SYSTEM \""^ dtdname ^ "\">\n");
376 xml_for_current_proof_type
380 | C.AConstant (id,idbody,n,bo,ty,params,obj_attrs) ->
381 let params' = param_attribute_of_params params in
382 let xml_attrs = xml_of_attrs obj_attrs in
389 "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n" ;
391 ("<!DOCTYPE ConstantBody SYSTEM \"" ^ dtdname ^ "\">\n") ;
392 X.xml_nempty "ConstantBody"
393 [None,"for",UriManager.string_of_uri uri ;
394 None,"params",params' ; None,"id", id]
395 [< print_term ?ids_to_inner_sorts bo >]
399 [< X.xml_cdata "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n" ;
400 X.xml_cdata ("<!DOCTYPE ConstantType SYSTEM \""^ dtdname ^ "\">\n");
401 X.xml_nempty "ConstantType"
402 [None,"name",n ; None,"params",params' ; None,"id", id]
403 [< xml_attrs; print_term ?ids_to_inner_sorts ty >]
407 | C.AVariable (id,n,bo,ty,params,obj_attrs) ->
408 let params' = param_attribute_of_params params in
409 let xml_attrs = xml_of_attrs obj_attrs in
414 X.xml_nempty "body" [] [< print_term ?ids_to_inner_sorts bo >]
417 [< X.xml_cdata "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n" ;
418 X.xml_cdata ("<!DOCTYPE Variable SYSTEM \"" ^ dtdname ^ "\">\n");
419 X.xml_nempty "Variable"
420 [None,"name",n ; None,"params",params' ; None,"id", id]
422 X.xml_nempty "type" [] (print_term ?ids_to_inner_sorts ty)
427 | C.AInductiveDefinition (id,tys,params,nparams,obj_attrs) ->
428 let params' = param_attribute_of_params params in
429 let xml_attrs = xml_of_attrs obj_attrs in
430 [< X.xml_cdata "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n" ;
432 ("<!DOCTYPE InductiveDefinition SYSTEM \"" ^ dtdname ^ "\">\n") ;
433 X.xml_nempty "InductiveDefinition"
434 [None,"noParams",string_of_int nparams ;
436 None,"params",params']
439 (fun i (id,typename,finite,arity,cons) ->
441 X.xml_nempty "InductiveType"
442 [None,"id",id ; None,"name",typename ;
443 None,"inductive",(string_of_bool finite)
445 [< X.xml_nempty "arity" []
446 (print_term ?ids_to_inner_sorts arity) ;
450 X.xml_nempty "Constructor"
452 (print_term ?ids_to_inner_sorts lc)
464 print_inner_types curi ~ids_to_inner_sorts ~ids_to_inner_types
465 ~ask_dtd_to_the_getter
467 let module C2A = Cic2acic in
468 let module X = Xml in
469 let dtdname = dtdname ~ask_dtd_to_the_getter "cictypes.dtd" in
470 [< X.xml_cdata "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n" ;
472 ("<!DOCTYPE InnerTypes SYSTEM \"" ^ dtdname ^ "\">\n") ;
473 X.xml_nempty "InnerTypes" [None,"of",UriManager.string_of_uri curi]
475 (fun id {C2A.annsynthesized = synty ; C2A.annexpected = expty} x ->
477 X.xml_nempty "TYPE" [None,"of",id]
478 [< X.xml_nempty "synthesized" []
479 [< print_term ~ids_to_inner_sorts synty >] ;
482 | Some expty' -> X.xml_nempty "expected" []
483 [< print_term ~ids_to_inner_sorts expty' >]
486 ) ids_to_inner_types [<>]