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 ["value",(string_of_int n) ; "binder",b ; "id",id ; "idref",idref ;
54 | C.AVar (id,uri,exp_named_subst) ->
55 let sort = Hashtbl.find ids_to_inner_sorts id in
57 (X.xml_empty "VAR" ["uri",U.string_of_uri uri;"id",id;"sort",sort])
60 let sort = Hashtbl.find ids_to_inner_sorts id in
61 X.xml_nempty "META" ["no",(string_of_int n) ; "id",id ; "sort",sort]
66 [< i ; X.xml_nempty "substitution" [] (aux t') >]
68 [< i ; X.xml_empty "substitution" [] >]
77 X.xml_empty "SORT" ["value",(string_of_sort s) ; "id",id]
78 | C.AImplicit _ -> raise NotImplemented
79 | C.AProd (last_id,_,_,_) as prods ->
83 let prods,t' = eat_prods t in
87 let prods,t = eat_prods prods in
88 let sort = Hashtbl.find ids_to_inner_sorts last_id in
89 X.xml_nempty "PROD" ["type",sort]
91 (fun i (id,binder,s) ->
93 Hashtbl.find ids_to_inner_sorts (Cic2acic.source_id_of_id id)
96 ("id",id)::("type",sort)::
99 | C.Name b -> ["binder",b]
101 [< i ; X.xml_nempty "decl" attrs (aux s) >]
103 X.xml_nempty "target" [] (aux t)
105 | C.ACast (id,v,t) ->
106 let sort = Hashtbl.find ids_to_inner_sorts id in
107 X.xml_nempty "CAST" ["id",id ; "sort",sort]
108 [< X.xml_nempty "term" [] (aux v) ;
109 X.xml_nempty "type" [] (aux t)
111 | C.ALambda (last_id,_,_,_) as lambdas ->
112 let rec eat_lambdas =
114 C.ALambda (id,n,s,t) ->
115 let lambdas,t' = eat_lambdas t in
119 let lambdas,t = eat_lambdas lambdas in
120 let sort = Hashtbl.find ids_to_inner_sorts last_id in
121 X.xml_nempty "LAMBDA" ["sort",sort]
123 (fun i (id,binder,s) ->
125 Hashtbl.find ids_to_inner_sorts (Cic2acic.source_id_of_id id)
128 ("id",id)::("type",sort)::
131 | C.Name b -> ["binder",b]
133 [< i ; X.xml_nempty "decl" attrs (aux s) >]
135 X.xml_nempty "target" [] (aux t)
137 | C.ALetIn (xid,C.Anonymous,s,t) ->
139 | C.ALetIn (last_id,C.Name _,_,_) as letins ->
142 C.ALetIn (id,n,s,t) ->
143 let letins,t' = eat_letins t in
147 let letins,t = eat_letins letins in
148 let sort = Hashtbl.find ids_to_inner_sorts last_id in
149 X.xml_nempty "LETIN" ["sort",sort]
151 (fun i (id,binder,s) ->
152 let sort = Hashtbl.find ids_to_inner_sorts id in
154 ("id",id)::("sort",sort)::
157 | C.Name b -> ["binder",b]
159 [< i ; X.xml_nempty "def" attrs (aux s) >]
161 X.xml_nempty "target" [] (aux t)
164 let sort = Hashtbl.find ids_to_inner_sorts id in
165 X.xml_nempty "APPLY" ["id",id ; "sort",sort]
166 [< (List.fold_right (fun x i -> [< (aux x) ; i >]) li [<>])
168 | C.AConst (id,uri,exp_named_subst) ->
169 let sort = Hashtbl.find ids_to_inner_sorts id in
172 ["uri", (U.string_of_uri uri) ; "id",id ; "sort",sort]
174 | C.AMutInd (id,uri,i,exp_named_subst) ->
176 (X.xml_empty "MUTIND"
177 ["uri", (U.string_of_uri uri) ;
178 "noType",(string_of_int i) ;
181 | C.AMutConstruct (id,uri,i,j,exp_named_subst) ->
182 let sort = Hashtbl.find ids_to_inner_sorts id in
184 (X.xml_empty "MUTCONSTRUCT"
185 ["uri", (U.string_of_uri uri) ;
186 "noType",(string_of_int i) ; "noConstr",(string_of_int j) ;
187 "id",id ; "sort",sort]
189 | C.AMutCase (id,uri,typeno,ty,te,patterns) ->
190 let sort = Hashtbl.find ids_to_inner_sorts id in
191 X.xml_nempty "MUTCASE"
192 ["uriType",(U.string_of_uri uri) ;
193 "noType", (string_of_int typeno) ;
194 "id", id ; "sort",sort]
195 [< X.xml_nempty "patternsType" [] [< (aux ty) >] ;
196 X.xml_nempty "inductiveTerm" [] [< (aux te) >] ;
198 (fun x i -> [< X.xml_nempty "pattern" [] [< aux x >] ; i>])
201 | C.AFix (id, no, funs) ->
202 let sort = Hashtbl.find ids_to_inner_sorts id in
204 ["noFun", (string_of_int no) ; "id",id ; "sort",sort]
206 (fun (id,fi,ai,ti,bi) i ->
207 [< X.xml_nempty "FixFunction"
208 ["id",id ; "name", fi ; "recIndex", (string_of_int ai)]
209 [< X.xml_nempty "type" [] [< aux ti >] ;
210 X.xml_nempty "body" [] [< aux bi >]
216 | C.ACoFix (id,no,funs) ->
217 let sort = Hashtbl.find ids_to_inner_sorts id in
219 ["noFun", (string_of_int no) ; "id",id ; "sort",sort]
221 (fun (id,fi,ti,bi) i ->
222 [< X.xml_nempty "CofixFunction" ["id",id ; "name", fi]
223 [< X.xml_nempty "type" [] [< aux ti >] ;
224 X.xml_nempty "body" [] [< aux bi >]
230 and aux_subst buri target subst =
231 (*CSC: I have now no way to assign an ID to the explicit named substitution *)
236 Xml.xml_nempty "instantiate"
237 (match id with None -> [] | Some id -> ["id",id])
243 Str.split (Str.regexp "/") (UriManager.string_of_uri buri) in
245 Str.split (Str.regexp "/") (UriManager.string_of_uri uri) in
246 let rec find_relUri buri_frags uri_frags =
247 match buri_frags,uri_frags with
248 [_], _ -> String.concat "/" uri_frags
249 | he1::tl1, he2::tl2 ->
252 | _,_ -> assert false (* uri is not relative to buri *)
254 find_relUri buri_frags uri_frags
256 [< i ; Xml.xml_nempty "arg" ["relUri", relUri] (aux arg) >]
263 let print_object uri ~ids_to_inner_sorts ~ask_dtd_to_the_getter obj =
264 let module C = Cic in
265 let module X = Xml in
266 let module U = UriManager in
267 let dtdname = dtdname ~ask_dtd_to_the_getter "cic.dtd" in
269 C.ACurrentProof (id,idbody,n,conjectures,bo,ty,params) ->
270 let params' = param_attribute_of_params params in
271 let xml_for_current_proof_body =
272 (*CSC: Should the CurrentProof also have the list of variables it depends on? *)
273 (*CSC: I think so. Not implemented yet. *)
274 X.xml_nempty "CurrentProof"
275 ["of",UriManager.string_of_uri uri ; "id", id]
277 (fun i (cid,n,canonical_context,t) ->
279 X.xml_nempty "Conjecture"
280 ["id", cid ; "no",(string_of_int n)]
284 Some (n,C.ADecl t) ->
287 C.Name n' -> ["id",hid;"name",n']
288 | C.Anonymous -> ["id",hid])
289 (print_term ids_to_inner_sorts t)
290 | Some (n,C.ADef t) ->
293 C.Name n' -> ["id",hid;"name",n']
294 | C.Anonymous -> ["id",hid])
295 (print_term ids_to_inner_sorts t)
296 | None -> X.xml_empty "Hidden" ["id",hid]
300 ) [< >] canonical_context ;
301 X.xml_nempty "Goal" []
302 (print_term ids_to_inner_sorts t)
306 X.xml_nempty "body" [] (print_term ids_to_inner_sorts bo) >]
308 let xml_for_current_proof_type =
309 X.xml_nempty "ConstantType" ["name",n ; "params",params' ; "id", id]
310 (print_term ids_to_inner_sorts ty)
313 [< X.xml_cdata "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n" ;
314 X.xml_cdata ("<!DOCTYPE CurrentProof SYSTEM \""^ dtdname ^ "\">\n");
315 xml_for_current_proof_body
318 [< X.xml_cdata "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n" ;
319 X.xml_cdata ("<!DOCTYPE ConstantType SYSTEM \""^ dtdname ^ "\">\n");
320 xml_for_current_proof_type
324 | C.AConstant (id,idbody,n,bo,ty,params) ->
325 let params' = param_attribute_of_params params in
332 "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n" ;
334 ("<!DOCTYPE ConstantBody SYSTEM \"" ^ dtdname ^ "\">\n") ;
335 X.xml_nempty "ConstantBody"
336 ["for",UriManager.string_of_uri uri ; "params",params' ;
338 [< print_term ids_to_inner_sorts bo >]
342 [< X.xml_cdata "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n" ;
343 X.xml_cdata ("<!DOCTYPE ConstantType SYSTEM \""^ dtdname ^ "\">\n");
344 X.xml_nempty "ConstantType"
345 ["name",n ; "params",params' ; "id", id]
346 [< print_term ids_to_inner_sorts ty >]
350 | C.AVariable (id,n,bo,ty,params) ->
351 let params' = param_attribute_of_params params in
356 X.xml_nempty "body" [] [< print_term ids_to_inner_sorts bo >]
359 [< X.xml_cdata "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n" ;
360 X.xml_cdata ("<!DOCTYPE Variable SYSTEM \"" ^ dtdname ^ "\">\n");
361 X.xml_nempty "Variable"
362 ["name",n ; "params",params' ; "id", id]
364 X.xml_nempty "type" [] (print_term ids_to_inner_sorts ty)
369 | C.AInductiveDefinition (id,tys,params,nparams) ->
370 let params' = param_attribute_of_params params in
371 [< X.xml_cdata "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n" ;
373 ("<!DOCTYPE InductiveDefinition SYSTEM \"" ^ dtdname ^ "\">\n") ;
374 X.xml_nempty "InductiveDefinition"
375 ["noParams",string_of_int nparams ;
379 (fun i (id,typename,finite,arity,cons) ->
381 X.xml_nempty "InductiveType"
382 ["id",id ; "name",typename ;
383 "inductive",(string_of_bool finite)
385 [< X.xml_nempty "arity" []
386 (print_term ids_to_inner_sorts arity) ;
390 X.xml_nempty "Constructor"
392 (print_term ids_to_inner_sorts lc)
404 print_inner_types curi ~ids_to_inner_sorts ~ids_to_inner_types
405 ~ask_dtd_to_the_getter
407 let module C2A = Cic2acic in
408 let module X = Xml in
409 let dtdname = dtdname ~ask_dtd_to_the_getter "cictypes.dtd" in
410 [< X.xml_cdata "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n" ;
412 ("<!DOCTYPE InnerTypes SYSTEM \"" ^ dtdname ^ "\">\n") ;
413 X.xml_nempty "InnerTypes" ["of",UriManager.string_of_uri curi]
415 (fun id {C2A.annsynthesized = synty ; C2A.annexpected = expty} x ->
417 X.xml_nempty "TYPE" ["of",id]
418 [< X.xml_nempty "synthesized" []
419 [< print_term ids_to_inner_sorts synty >] ;
422 | Some expty' -> X.xml_nempty "expected" [] [< print_term ids_to_inner_sorts expty' >]
425 ) ids_to_inner_types [<>]