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 -> "coercion"
265 | `Elim Cic.Prop -> "elimProp"
266 | `Elim Cic.CProp -> "elimCProp"
267 | `Elim Cic.Set -> "elimSet"
268 | `Elim (Cic.Type _) -> "elimType"
269 | `Record -> "record"
270 | `Projection -> "projection"
272 let xml_attr_of = function
273 | `Generated -> None, "generated", "true"
274 | `Class c -> None, "class", class_of c
276 let xml_attrs = List.map xml_attr_of attributes in
277 Xml.xml_empty "attributes" xml_attrs
279 let print_object uri ~ids_to_inner_sorts ~ask_dtd_to_the_getter obj =
281 Cic2acic.string_of_sort (Hashtbl.find ids_to_inner_sorts id)
283 let module C = Cic in
284 let module X = Xml in
285 let module U = UriManager in
286 let dtdname = dtdname ~ask_dtd_to_the_getter "cic.dtd" in
288 C.ACurrentProof (id,idbody,n,conjectures,bo,ty,params,obj_attrs) ->
289 let params' = param_attribute_of_params params in
290 let xml_attrs = xml_of_attrs obj_attrs in
291 let xml_for_current_proof_body =
292 (*CSC: Should the CurrentProof also have the list of variables it depends on? *)
293 (*CSC: I think so. Not implemented yet. *)
294 X.xml_nempty "CurrentProof"
295 [None,"of",UriManager.string_of_uri uri ; None,"id", id]
298 (fun i (cid,n,canonical_context,t) ->
300 X.xml_nempty "Conjecture"
301 [None,"id",cid ; None,"no",(string_of_int n)]
305 Some (n,C.ADecl t) ->
309 [None,"id",hid;None,"name",n']
310 | C.Anonymous -> [None,"id",hid])
311 (print_term ids_to_inner_sorts t)
312 | Some (n,C.ADef t) ->
316 [None,"id",hid;None,"name",n']
317 | C.Anonymous -> [None,"id",hid])
318 (print_term ids_to_inner_sorts t)
319 | None -> X.xml_empty "Hidden" [None,"id",hid]
323 ) [< >] canonical_context ;
324 X.xml_nempty "Goal" []
325 (print_term ids_to_inner_sorts t)
329 X.xml_nempty "body" [] (print_term ids_to_inner_sorts bo) >]
331 let xml_for_current_proof_type =
332 X.xml_nempty "ConstantType"
333 [None,"name",n ; None,"params",params' ; None,"id", id]
334 (print_term ids_to_inner_sorts ty)
337 [< X.xml_cdata "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n" ;
338 X.xml_cdata ("<!DOCTYPE CurrentProof SYSTEM \""^ dtdname ^ "\">\n");
339 xml_for_current_proof_body
342 [< X.xml_cdata "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n" ;
343 X.xml_cdata ("<!DOCTYPE ConstantType SYSTEM \""^ dtdname ^ "\">\n");
344 xml_for_current_proof_type
348 | C.AConstant (id,idbody,n,bo,ty,params,obj_attrs) ->
349 let params' = param_attribute_of_params params in
350 let xml_attrs = xml_of_attrs obj_attrs in
357 "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n" ;
359 ("<!DOCTYPE ConstantBody SYSTEM \"" ^ dtdname ^ "\">\n") ;
360 X.xml_nempty "ConstantBody"
361 [None,"for",UriManager.string_of_uri uri ;
362 None,"params",params' ; None,"id", id]
363 [< print_term ids_to_inner_sorts bo >]
367 [< X.xml_cdata "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n" ;
368 X.xml_cdata ("<!DOCTYPE ConstantType SYSTEM \""^ dtdname ^ "\">\n");
369 X.xml_nempty "ConstantType"
370 [None,"name",n ; None,"params",params' ; None,"id", id]
371 [< xml_attrs; print_term ids_to_inner_sorts ty >]
375 | C.AVariable (id,n,bo,ty,params,obj_attrs) ->
376 let params' = param_attribute_of_params params in
377 let xml_attrs = xml_of_attrs obj_attrs in
382 X.xml_nempty "body" [] [< print_term ids_to_inner_sorts bo >]
385 [< X.xml_cdata "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n" ;
386 X.xml_cdata ("<!DOCTYPE Variable SYSTEM \"" ^ dtdname ^ "\">\n");
387 X.xml_nempty "Variable"
388 [None,"name",n ; None,"params",params' ; None,"id", id]
390 X.xml_nempty "type" [] (print_term ids_to_inner_sorts ty)
395 | C.AInductiveDefinition (id,tys,params,nparams,obj_attrs) ->
396 let params' = param_attribute_of_params params in
397 let xml_attrs = xml_of_attrs obj_attrs in
398 [< X.xml_cdata "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n" ;
400 ("<!DOCTYPE InductiveDefinition SYSTEM \"" ^ dtdname ^ "\">\n") ;
401 X.xml_nempty "InductiveDefinition"
402 [None,"noParams",string_of_int nparams ;
404 None,"params",params']
407 (fun i (id,typename,finite,arity,cons) ->
409 X.xml_nempty "InductiveType"
410 [None,"id",id ; None,"name",typename ;
411 None,"inductive",(string_of_bool finite)
413 [< X.xml_nempty "arity" []
414 (print_term ids_to_inner_sorts arity) ;
418 X.xml_nempty "Constructor"
420 (print_term ids_to_inner_sorts lc)
432 print_inner_types curi ~ids_to_inner_sorts ~ids_to_inner_types
433 ~ask_dtd_to_the_getter
435 let module C2A = Cic2acic in
436 let module X = Xml in
437 let dtdname = dtdname ~ask_dtd_to_the_getter "cictypes.dtd" in
438 [< X.xml_cdata "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n" ;
440 ("<!DOCTYPE InnerTypes SYSTEM \"" ^ dtdname ^ "\">\n") ;
441 X.xml_nempty "InnerTypes" [None,"of",UriManager.string_of_uri curi]
443 (fun id {C2A.annsynthesized = synty ; C2A.annexpected = expty} x ->
445 X.xml_nempty "TYPE" [None,"of",id]
446 [< X.xml_nempty "synthesized" []
447 [< print_term ids_to_inner_sorts synty >] ;
450 | Some expty' -> X.xml_nempty "expected" []
451 [< print_term ids_to_inner_sorts expty' >]
454 ) ids_to_inner_types [<>]