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 dtdname ~ask_dtd_to_the_getter dtd =
32 if ask_dtd_to_the_getter then
33 Configuration.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" [] >]
79 X.xml_empty "SORT" [None,"value",(string_of_sort s) ; None,"id",id]
80 | C.AImplicit _ -> raise NotImplemented
81 | C.AProd (last_id,_,_,_) as prods ->
85 let prods,t' = eat_prods t in
89 let prods,t = eat_prods prods in
90 let sort = Hashtbl.find ids_to_inner_sorts last_id in
91 X.xml_nempty "PROD" [None,"type",sort]
93 (fun i (id,binder,s) ->
95 Hashtbl.find ids_to_inner_sorts (Cic2acic.source_id_of_id id)
98 (None,"id",id)::(None,"type",sort)::
101 | C.Name b -> [None,"binder",b]
103 [< i ; X.xml_nempty "decl" attrs (aux s) >]
105 X.xml_nempty "target" [] (aux t)
107 | C.ACast (id,v,t) ->
108 let sort = Hashtbl.find ids_to_inner_sorts id in
109 X.xml_nempty "CAST" [None,"id",id ; None,"sort",sort]
110 [< X.xml_nempty "term" [] (aux v) ;
111 X.xml_nempty "type" [] (aux t)
113 | C.ALambda (last_id,_,_,_) as lambdas ->
114 let rec eat_lambdas =
116 C.ALambda (id,n,s,t) ->
117 let lambdas,t' = eat_lambdas t in
121 let lambdas,t = eat_lambdas lambdas in
122 let sort = Hashtbl.find ids_to_inner_sorts last_id in
123 X.xml_nempty "LAMBDA" [None,"sort",sort]
125 (fun i (id,binder,s) ->
127 Hashtbl.find ids_to_inner_sorts (Cic2acic.source_id_of_id id)
130 (None,"id",id)::(None,"type",sort)::
133 | C.Name b -> [None,"binder",b]
135 [< i ; X.xml_nempty "decl" attrs (aux s) >]
137 X.xml_nempty "target" [] (aux t)
139 | C.ALetIn (xid,C.Anonymous,s,t) ->
141 | C.ALetIn (last_id,C.Name _,_,_) as letins ->
144 C.ALetIn (id,n,s,t) ->
145 let letins,t' = eat_letins t in
149 let letins,t = eat_letins letins in
150 let sort = Hashtbl.find ids_to_inner_sorts last_id in
151 X.xml_nempty "LETIN" [None,"sort",sort]
153 (fun i (id,binder,s) ->
154 let sort = Hashtbl.find ids_to_inner_sorts id in
156 (None,"id",id)::(None,"sort",sort)::
159 | C.Name b -> [None,"binder",b]
161 [< i ; X.xml_nempty "def" attrs (aux s) >]
163 X.xml_nempty "target" [] (aux t)
166 let sort = Hashtbl.find ids_to_inner_sorts id in
167 X.xml_nempty "APPLY" [None,"id",id ; None,"sort",sort]
168 [< (List.fold_right (fun x i -> [< (aux x) ; i >]) li [<>])
170 | C.AConst (id,uri,exp_named_subst) ->
171 let sort = Hashtbl.find ids_to_inner_sorts id in
174 [None,"uri",(U.string_of_uri uri) ; None,"id",id ; None,"sort",sort]
176 | C.AMutInd (id,uri,i,exp_named_subst) ->
178 (X.xml_empty "MUTIND"
179 [None, "uri", (U.string_of_uri uri) ;
180 None, "noType", (string_of_int i) ;
183 | C.AMutConstruct (id,uri,i,j,exp_named_subst) ->
184 let sort = Hashtbl.find ids_to_inner_sorts id in
186 (X.xml_empty "MUTCONSTRUCT"
187 [None,"uri", (U.string_of_uri uri) ;
188 None,"noType",(string_of_int i) ;
189 None,"noConstr",(string_of_int j) ;
190 None,"id",id ; None,"sort",sort]
192 | C.AMutCase (id,uri,typeno,ty,te,patterns) ->
193 let sort = Hashtbl.find ids_to_inner_sorts id in
194 X.xml_nempty "MUTCASE"
195 [None,"uriType",(U.string_of_uri uri) ;
196 None,"noType", (string_of_int typeno) ;
197 None,"id", id ; None,"sort",sort]
198 [< X.xml_nempty "patternsType" [] [< (aux ty) >] ;
199 X.xml_nempty "inductiveTerm" [] [< (aux te) >] ;
201 (fun x i -> [< X.xml_nempty "pattern" [] [< aux x >] ; i>])
204 | C.AFix (id, no, funs) ->
205 let sort = Hashtbl.find ids_to_inner_sorts id in
207 [None,"noFun", (string_of_int no) ; None,"id",id ; None,"sort",sort]
209 (fun (id,fi,ai,ti,bi) i ->
210 [< X.xml_nempty "FixFunction"
211 [None,"id",id ; None,"name", fi ;
212 None,"recIndex", (string_of_int ai)]
213 [< X.xml_nempty "type" [] [< aux ti >] ;
214 X.xml_nempty "body" [] [< aux bi >]
220 | C.ACoFix (id,no,funs) ->
221 let sort = Hashtbl.find ids_to_inner_sorts id in
223 [None,"noFun", (string_of_int no) ; None,"id",id ; None,"sort",sort]
225 (fun (id,fi,ti,bi) i ->
226 [< X.xml_nempty "CofixFunction" [None,"id",id ; None,"name", fi]
227 [< X.xml_nempty "type" [] [< aux ti >] ;
228 X.xml_nempty "body" [] [< aux bi >]
234 and aux_subst buri target subst =
235 (*CSC: I have now no way to assign an ID to the explicit named substitution *)
240 Xml.xml_nempty "instantiate"
241 (match id with None -> [] | Some id -> [None,"id",id])
247 Str.split (Str.regexp "/") (UriManager.string_of_uri buri) in
249 Str.split (Str.regexp "/") (UriManager.string_of_uri uri) in
250 let rec find_relUri buri_frags uri_frags =
251 match buri_frags,uri_frags with
252 [_], _ -> String.concat "/" uri_frags
253 | he1::tl1, he2::tl2 ->
256 | _,_ -> assert false (* uri is not relative to buri *)
258 find_relUri buri_frags uri_frags
260 [< i ; Xml.xml_nempty "arg" [None,"relUri", relUri] (aux arg) >]
267 let print_object uri ~ids_to_inner_sorts ~ask_dtd_to_the_getter obj =
268 let module C = Cic in
269 let module X = Xml in
270 let module U = UriManager in
271 let dtdname = dtdname ~ask_dtd_to_the_getter "cic.dtd" in
273 C.ACurrentProof (id,idbody,n,conjectures,bo,ty,params) ->
274 let params' = param_attribute_of_params params in
275 let xml_for_current_proof_body =
276 (*CSC: Should the CurrentProof also have the list of variables it depends on? *)
277 (*CSC: I think so. Not implemented yet. *)
278 X.xml_nempty "CurrentProof"
279 [None,"of",UriManager.string_of_uri uri ; None,"id", id]
281 (fun i (cid,n,canonical_context,t) ->
283 X.xml_nempty "Conjecture"
284 [None,"id",cid ; None,"no",(string_of_int n)]
288 Some (n,C.ADecl t) ->
292 [None,"id",hid;None,"name",n']
293 | C.Anonymous -> [None,"id",hid])
294 (print_term ids_to_inner_sorts t)
295 | Some (n,C.ADef t) ->
299 [None,"id",hid;None,"name",n']
300 | C.Anonymous -> [None,"id",hid])
301 (print_term ids_to_inner_sorts t)
302 | None -> X.xml_empty "Hidden" [None,"id",hid]
306 ) [< >] canonical_context ;
307 X.xml_nempty "Goal" []
308 (print_term ids_to_inner_sorts t)
312 X.xml_nempty "body" [] (print_term ids_to_inner_sorts bo) >]
314 let xml_for_current_proof_type =
315 X.xml_nempty "ConstantType"
316 [None,"name",n ; None,"params",params' ; None,"id", id]
317 (print_term ids_to_inner_sorts ty)
320 [< X.xml_cdata "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n" ;
321 X.xml_cdata ("<!DOCTYPE CurrentProof SYSTEM \""^ dtdname ^ "\">\n");
322 xml_for_current_proof_body
325 [< X.xml_cdata "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n" ;
326 X.xml_cdata ("<!DOCTYPE ConstantType SYSTEM \""^ dtdname ^ "\">\n");
327 xml_for_current_proof_type
331 | C.AConstant (id,idbody,n,bo,ty,params) ->
332 let params' = param_attribute_of_params params in
339 "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n" ;
341 ("<!DOCTYPE ConstantBody SYSTEM \"" ^ dtdname ^ "\">\n") ;
342 X.xml_nempty "ConstantBody"
343 [None,"for",UriManager.string_of_uri uri ;
344 None,"params",params' ; None,"id", id]
345 [< print_term ids_to_inner_sorts bo >]
349 [< X.xml_cdata "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n" ;
350 X.xml_cdata ("<!DOCTYPE ConstantType SYSTEM \""^ dtdname ^ "\">\n");
351 X.xml_nempty "ConstantType"
352 [None,"name",n ; None,"params",params' ; None,"id", id]
353 [< print_term ids_to_inner_sorts ty >]
357 | C.AVariable (id,n,bo,ty,params) ->
358 let params' = param_attribute_of_params params in
363 X.xml_nempty "body" [] [< print_term ids_to_inner_sorts bo >]
366 [< X.xml_cdata "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n" ;
367 X.xml_cdata ("<!DOCTYPE Variable SYSTEM \"" ^ dtdname ^ "\">\n");
368 X.xml_nempty "Variable"
369 [None,"name",n ; None,"params",params' ; None,"id", id]
371 X.xml_nempty "type" [] (print_term ids_to_inner_sorts ty)
376 | C.AInductiveDefinition (id,tys,params,nparams) ->
377 let params' = param_attribute_of_params params in
378 [< X.xml_cdata "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n" ;
380 ("<!DOCTYPE InductiveDefinition SYSTEM \"" ^ dtdname ^ "\">\n") ;
381 X.xml_nempty "InductiveDefinition"
382 [None,"noParams",string_of_int nparams ;
384 None,"params",params']
386 (fun i (id,typename,finite,arity,cons) ->
388 X.xml_nempty "InductiveType"
389 [None,"id",id ; None,"name",typename ;
390 None,"inductive",(string_of_bool finite)
392 [< X.xml_nempty "arity" []
393 (print_term ids_to_inner_sorts arity) ;
397 X.xml_nempty "Constructor"
399 (print_term ids_to_inner_sorts lc)
411 print_inner_types curi ~ids_to_inner_sorts ~ids_to_inner_types
412 ~ask_dtd_to_the_getter
414 let module C2A = Cic2acic in
415 let module X = Xml in
416 let dtdname = dtdname ~ask_dtd_to_the_getter "cictypes.dtd" in
417 [< X.xml_cdata "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n" ;
419 ("<!DOCTYPE InnerTypes SYSTEM \"" ^ dtdname ^ "\">\n") ;
420 X.xml_nempty "InnerTypes" [None,"of",UriManager.string_of_uri curi]
422 (fun id {C2A.annsynthesized = synty ; C2A.annexpected = expty} x ->
424 X.xml_nempty "TYPE" [None,"of",id]
425 [< X.xml_nempty "synthesized" []
426 [< print_term ids_to_inner_sorts synty >] ;
429 | Some expty' -> X.xml_nempty "expected" [] [< print_term ids_to_inner_sorts expty' >]
432 ) ids_to_inner_types [<>]