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 = "http://localhost:8081/getdtd?uri=cic.dtd";;
33 let param_attribute_of_params params =
34 String.concat " " (List.map UriManager.string_of_uri params)
37 (*CSC ottimizzazione: al posto di curi cdepth (vedi codice) *)
38 let print_term ~ids_to_inner_sorts =
42 let module U = UriManager in
44 C.ARel (id,idref,n,b) ->
45 let sort = Hashtbl.find ids_to_inner_sorts id in
47 ["value",(string_of_int n) ; "binder",b ; "id",id ; "idref",idref ;
49 | C.AVar (id,uri,exp_named_subst) ->
50 let sort = Hashtbl.find ids_to_inner_sorts id in
52 (X.xml_empty "VAR" ["uri",U.string_of_uri uri;"id",id;"sort",sort])
55 let sort = Hashtbl.find ids_to_inner_sorts id in
56 X.xml_nempty "META" ["no",(string_of_int n) ; "id",id ; "sort",sort]
61 [< i ; X.xml_nempty "substitution" [] (aux t') >]
63 [< i ; X.xml_empty "substitution" [] >]
72 X.xml_empty "SORT" ["value",(string_of_sort s) ; "id",id]
73 | C.AImplicit _ -> raise NotImplemented
74 | C.AProd (last_id,_,_,_) as prods ->
78 let prods,t' = eat_prods t in
82 let prods,t = eat_prods prods in
83 let sort = Hashtbl.find ids_to_inner_sorts last_id in
84 X.xml_nempty "PROD" ["type",sort]
86 (fun i (id,binder,s) ->
87 let sort = Hashtbl.find ids_to_inner_sorts id in
89 ("id",id)::("type",sort)::
92 | C.Name b -> ["binder",b]
94 [< i ; X.xml_nempty "decl" attrs (aux s) >]
96 X.xml_nempty "target" [] (aux t)
99 let sort = Hashtbl.find ids_to_inner_sorts id in
100 X.xml_nempty "CAST" ["id",id ; "sort",sort]
101 [< X.xml_nempty "term" [] (aux v) ;
102 X.xml_nempty "type" [] (aux t)
104 | C.ALambda (last_id,_,_,_) as lambdas ->
105 let rec eat_lambdas =
107 C.ALambda (id,n,s,t) ->
108 let lambdas,t' = eat_lambdas t in
112 let lambdas,t = eat_lambdas lambdas in
113 let sort = Hashtbl.find ids_to_inner_sorts last_id in
114 X.xml_nempty "LAMBDA" ["sort",sort]
116 (fun i (id,binder,s) ->
117 let sort = Hashtbl.find ids_to_inner_sorts id in
119 ("id",id)::("type",sort)::
122 | C.Name b -> ["binder",b]
124 [< i ; X.xml_nempty "decl" attrs (aux s) >]
126 X.xml_nempty "target" [] (aux t)
128 | C.ALetIn (xid,C.Anonymous,s,t) ->
130 | C.ALetIn (last_id,C.Name _,_,_) as letins ->
133 C.ALetIn (id,n,s,t) ->
134 let letins,t' = eat_letins t in
138 let letins,t = eat_letins letins in
139 let sort = Hashtbl.find ids_to_inner_sorts last_id in
140 X.xml_nempty "LETIN" ["sort",sort]
142 (fun i (id,binder,s) ->
143 let sort = Hashtbl.find ids_to_inner_sorts id in
145 ("id",id)::("sort",sort)::
148 | C.Name b -> ["binder",b]
150 [< i ; X.xml_nempty "def" attrs (aux s) >]
152 X.xml_nempty "target" [] (aux t)
155 let sort = Hashtbl.find ids_to_inner_sorts id in
156 X.xml_nempty "APPLY" ["id",id ; "sort",sort]
157 [< (List.fold_right (fun x i -> [< (aux x) ; i >]) li [<>])
159 | C.AConst (id,uri,exp_named_subst) ->
160 let sort = Hashtbl.find ids_to_inner_sorts id in
163 ["uri", (U.string_of_uri uri) ; "id",id ; "sort",sort]
165 | C.AMutInd (id,uri,i,exp_named_subst) ->
167 (X.xml_empty "MUTIND"
168 ["uri", (U.string_of_uri uri) ;
169 "noType",(string_of_int i) ;
172 | C.AMutConstruct (id,uri,i,j,exp_named_subst) ->
173 let sort = Hashtbl.find ids_to_inner_sorts id in
175 (X.xml_empty "MUTCONSTRUCT"
176 ["uri", (U.string_of_uri uri) ;
177 "noType",(string_of_int i) ; "noConstr",(string_of_int j) ;
178 "id",id ; "sort",sort]
180 | C.AMutCase (id,uri,typeno,ty,te,patterns) ->
181 let sort = Hashtbl.find ids_to_inner_sorts id in
182 X.xml_nempty "MUTCASE"
183 ["uriType",(U.string_of_uri uri) ;
184 "noType", (string_of_int typeno) ;
185 "id", id ; "sort",sort]
186 [< X.xml_nempty "patternsType" [] [< (aux ty) >] ;
187 X.xml_nempty "inductiveTerm" [] [< (aux te) >] ;
189 (fun x i -> [< X.xml_nempty "pattern" [] [< aux x >] ; i>])
192 | C.AFix (id, no, funs) ->
193 let sort = Hashtbl.find ids_to_inner_sorts id in
195 ["noFun", (string_of_int no) ; "id",id ; "sort",sort]
197 (fun (id,fi,ai,ti,bi) i ->
198 [< X.xml_nempty "FixFunction"
199 ["id",id ; "name", fi ; "recIndex", (string_of_int ai)]
200 [< X.xml_nempty "type" [] [< aux ti >] ;
201 X.xml_nempty "body" [] [< aux bi >]
207 | C.ACoFix (id,no,funs) ->
208 let sort = Hashtbl.find ids_to_inner_sorts id in
210 ["noFun", (string_of_int no) ; "id",id ; "sort",sort]
212 (fun (id,fi,ti,bi) i ->
213 [< X.xml_nempty "CofixFunction" ["id",id ; "name", fi]
214 [< X.xml_nempty "type" [] [< aux ti >] ;
215 X.xml_nempty "body" [] [< aux bi >]
221 and aux_subst buri target subst =
222 (*CSC: I have now no way to assign an ID to the explicit named substitution *)
227 Xml.xml_nempty "instantiate"
228 (match id with None -> [] | Some id -> ["id",id])
234 Str.split (Str.regexp "/") (UriManager.string_of_uri buri) in
236 Str.split (Str.regexp "/") (UriManager.string_of_uri uri) in
237 let rec find_relUri buri_frags uri_frags =
238 match buri_frags,uri_frags with
239 [_], _ -> String.concat "/" uri_frags
240 | he1::tl1, he2::tl2 ->
243 | _,_ -> assert false (* uri is not relative to buri *)
245 find_relUri buri_frags uri_frags
247 [< i ; Xml.xml_nempty "arg" ["relUri", relUri] (aux arg) >]
254 exception NotImplemented;;
256 let print_object uri ~ids_to_inner_sorts =
258 let module C = Cic in
259 let module X = Xml in
260 let module U = UriManager in
262 C.ACurrentProof (id,idbody,n,conjectures,bo,ty,params) ->
263 let params' = param_attribute_of_params params in
264 let xml_for_current_proof_body =
265 (*CSC: Should the CurrentProof also have the list of variables it depends on? *)
266 (*CSC: I think so. Not implemented yet. *)
267 X.xml_nempty "CurrentProof"
268 ["of",UriManager.string_of_uri uri ; "id", id]
270 (fun i (cid,n,canonical_context,t) ->
272 X.xml_nempty "Conjecture"
273 ["id", cid ; "no",(string_of_int n)]
277 Some (n,C.ADecl t) ->
280 C.Name n' -> ["id",hid;"name",n']
281 | C.Anonymous -> ["id",hid])
282 (print_term ids_to_inner_sorts t)
283 | Some (n,C.ADef t) ->
286 C.Name n' -> ["id",hid;"name",n']
287 | C.Anonymous -> ["id",hid])
288 (print_term ids_to_inner_sorts t)
289 | None -> X.xml_empty "Hidden" ["id",hid]
293 ) [< >] canonical_context ;
294 X.xml_nempty "Goal" []
295 (print_term ids_to_inner_sorts t)
299 X.xml_nempty "body" [] (print_term ids_to_inner_sorts bo) >]
301 let xml_for_current_proof_type =
302 X.xml_nempty "ConstantType" ["name",n ; "params",params' ; "id", id]
303 (print_term ids_to_inner_sorts ty)
306 [< X.xml_cdata "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n" ;
307 X.xml_cdata ("<!DOCTYPE CurrentProof SYSTEM \""^dtdname ^"\">\n");
308 xml_for_current_proof_body
311 [< X.xml_cdata "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n" ;
313 ("<!DOCTYPE ConstantType SYSTEM \"" ^ dtdname ^ "\">\n");
314 xml_for_current_proof_type
318 | C.AConstant (id,idbody,n,bo,ty,params) ->
319 let params' = param_attribute_of_params params in
326 "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n" ;
328 ("<!DOCTYPE ConstantBody SYSTEM \"" ^ dtdname ^ "\">\n") ;
329 X.xml_nempty "ConstantBody"
330 ["for",UriManager.string_of_uri uri ; "params",params' ;
332 [< print_term ids_to_inner_sorts bo >]
336 [< X.xml_cdata "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n" ;
337 X.xml_cdata ("<!DOCTYPE ConstantType SYSTEM \""^dtdname ^"\">\n");
338 X.xml_nempty "ConstantType"
339 ["name",n ; "params",params' ; "id", id]
340 [< print_term ids_to_inner_sorts ty >]
344 | _ -> raise NotImplemented
349 let print_inner_types curi ~ids_to_inner_sorts ~ids_to_inner_types =
350 let module C2A = Cic2acic in
351 let module X = Xml in
352 X.xml_nempty "InnerTypes" ["of",UriManager.string_of_uri curi]
354 (fun id {C2A.annsynthesized = synty ; C2A.annexpected = expty} x ->
356 X.xml_nempty "TYPE" ["of",id]
357 [< print_term ids_to_inner_sorts synty ;
360 | Some expty' -> print_term ids_to_inner_sorts expty'
363 ) ids_to_inner_types [<>]