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 let print_object uri ~ids_to_inner_sorts =
256 let module C = Cic in
257 let module X = Xml in
258 let module U = UriManager in
260 C.ACurrentProof (id,idbody,n,conjectures,bo,ty,params) ->
261 let params' = param_attribute_of_params params in
262 let xml_for_current_proof_body =
263 (*CSC: Should the CurrentProof also have the list of variables it depends on? *)
264 (*CSC: I think so. Not implemented yet. *)
265 X.xml_nempty "CurrentProof"
266 ["of",UriManager.string_of_uri uri ; "id", id]
268 (fun i (cid,n,canonical_context,t) ->
270 X.xml_nempty "Conjecture"
271 ["id", cid ; "no",(string_of_int n)]
275 Some (n,C.ADecl t) ->
278 C.Name n' -> ["id",hid;"name",n']
279 | C.Anonymous -> ["id",hid])
280 (print_term ids_to_inner_sorts t)
281 | Some (n,C.ADef t) ->
284 C.Name n' -> ["id",hid;"name",n']
285 | C.Anonymous -> ["id",hid])
286 (print_term ids_to_inner_sorts t)
287 | None -> X.xml_empty "Hidden" ["id",hid]
291 ) [< >] canonical_context ;
292 X.xml_nempty "Goal" []
293 (print_term ids_to_inner_sorts t)
297 X.xml_nempty "body" [] (print_term ids_to_inner_sorts bo) >]
299 let xml_for_current_proof_type =
300 X.xml_nempty "ConstantType" ["name",n ; "params",params' ; "id", id]
301 (print_term ids_to_inner_sorts ty)
304 [< X.xml_cdata "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n" ;
305 X.xml_cdata ("<!DOCTYPE CurrentProof SYSTEM \""^dtdname ^"\">\n");
306 xml_for_current_proof_body
309 [< X.xml_cdata "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n" ;
311 ("<!DOCTYPE ConstantType SYSTEM \"" ^ dtdname ^ "\">\n");
312 xml_for_current_proof_type
316 | C.AConstant (id,idbody,n,bo,ty,params) ->
317 let params' = param_attribute_of_params params in
324 "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n" ;
326 ("<!DOCTYPE ConstantBody SYSTEM \"" ^ dtdname ^ "\">\n") ;
327 X.xml_nempty "ConstantBody"
328 ["for",UriManager.string_of_uri uri ; "params",params' ;
330 [< print_term ids_to_inner_sorts bo >]
334 [< X.xml_cdata "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n" ;
335 X.xml_cdata ("<!DOCTYPE ConstantType SYSTEM \""^dtdname ^"\">\n");
336 X.xml_nempty "ConstantType"
337 ["name",n ; "params",params' ; "id", id]
338 [< print_term ids_to_inner_sorts ty >]
342 | C.AVariable (id,n,bo,ty,params) ->
343 let params' = param_attribute_of_params params in
348 X.xml_nempty "body" [] [< print_term ids_to_inner_sorts bo >]
351 [< X.xml_cdata "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n" ;
352 X.xml_cdata ("<!DOCTYPE Variable SYSTEM \"" ^ dtdname ^ "\">\n");
353 X.xml_nempty "Variable"
354 ["name",n ; "params",params' ; "id", id]
356 X.xml_nempty "type" [] (print_term ids_to_inner_sorts ty)
361 | C.AInductiveDefinition (id,tys,params,nparams) ->
362 let params' = param_attribute_of_params params in
363 [< X.xml_cdata "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n" ;
364 X.xml_cdata ("<!DOCTYPE InductiveDefinition SYSTEM \"" ^
366 X.xml_nempty "InductiveDefinition"
367 ["noParams",string_of_int nparams ;
371 (fun i (id,typename,finite,arity,cons) ->
373 X.xml_nempty "InductiveType"
374 ["id",id ; "name",typename ;
375 "inductive",(string_of_bool finite)
377 [< X.xml_nempty "arity" []
378 (print_term ids_to_inner_sorts arity) ;
382 X.xml_nempty "Constructor"
384 (print_term ids_to_inner_sorts lc)
397 let print_inner_types curi ~ids_to_inner_sorts ~ids_to_inner_types =
398 let module C2A = Cic2acic in
399 let module X = Xml in
400 X.xml_nempty "InnerTypes" ["of",UriManager.string_of_uri curi]
402 (fun id {C2A.annsynthesized = synty ; C2A.annexpected = expty} x ->
404 X.xml_nempty "TYPE" ["of",id]
405 [< print_term ids_to_inner_sorts synty ;
408 | Some expty' -> print_term ids_to_inner_sorts expty'
411 ) ids_to_inner_types [<>]