1
(************************************************************************)
2
(* v * The Coq Proof Assistant / The Coq Development Team *)
3
(* <O___,, * CNRS-Ecole Polytechnique-INRIA Futurs-Universite Paris Sud *)
4
(* \VV/ **************************************************************)
5
(* // * The HELM Project / The EU MoWGLI Project *)
6
(* * University of Bologna *)
7
(************************************************************************)
8
(* This file is distributed under the terms of the *)
9
(* GNU Lesser General Public License Version 2.1 *)
11
(* Copyright (C) 2000-2004, HELM Team. *)
12
(* http://helm.cs.unibo.it *)
13
(************************************************************************)
15
(*CSC codice cut & paste da cicPp e xmlcommand *)
17
exception ImpossiblePossible;;
18
exception NotImplemented;;
19
let dtdname = "http://mowgli.cs.unibo.it/dtd/cic.dtd";;
20
let typesdtdname = "http://mowgli.cs.unibo.it/dtd/cictypes.dtd";;
22
let rec find_last_id =
24
[] -> Util.anomaly "find_last_id: empty list"
26
| _::tl -> find_last_id tl
29
let export_existential = string_of_int
31
let print_term ids_to_inner_sorts =
33
let module A = Acic in
34
let module N = Names in
37
A.ARel (id,n,idref,b) ->
38
let sort = Hashtbl.find ids_to_inner_sorts id in
40
["value",(string_of_int n) ; "binder",(N.string_of_id b) ;
41
"id",id ; "idref",idref; "sort",sort]
43
let sort = Hashtbl.find ids_to_inner_sorts id in
44
X.xml_empty "VAR" ["uri", uri ; "id",id ; "sort",sort]
46
let sort = Hashtbl.find ids_to_inner_sorts id in
48
["no",(export_existential n) ; "id",id ; "sort",sort]
51
[< i ; X.xml_nempty "substitution" [] (aux t) >]
55
match Term.family_of_sort s with
58
| Term.InType -> "Type"
60
X.xml_empty "SORT" ["value",string_of_sort ; "id",id]
61
| A.AProds (prods,t) ->
62
let last_id = find_last_id prods in
63
let sort = Hashtbl.find ids_to_inner_sorts last_id in
64
X.xml_nempty "PROD" ["type",sort]
66
(fun i (id,binder,s) ->
68
Hashtbl.find ids_to_inner_sorts (Cic2acic.source_id_of_id id)
71
("id",id)::("type",sort)::
74
| Names.Name b -> ["binder",Names.string_of_id b]
76
[< X.xml_nempty "decl" attrs (aux s) ; i >]
78
X.xml_nempty "target" [] (aux t)
81
let sort = Hashtbl.find ids_to_inner_sorts id in
82
X.xml_nempty "CAST" ["id",id ; "sort",sort]
83
[< X.xml_nempty "term" [] (aux v) ;
84
X.xml_nempty "type" [] (aux t)
86
| A.ALambdas (lambdas,t) ->
87
let last_id = find_last_id lambdas in
88
let sort = Hashtbl.find ids_to_inner_sorts last_id in
89
X.xml_nempty "LAMBDA" ["sort",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
| Names.Name b -> ["binder",Names.string_of_id b]
101
[< X.xml_nempty "decl" attrs (aux s) ; i >]
103
X.xml_nempty "target" [] (aux t)
105
| A.ALetIns (letins,t) ->
106
let last_id = find_last_id letins in
107
let sort = Hashtbl.find ids_to_inner_sorts last_id in
108
X.xml_nempty "LETIN" ["sort",sort]
110
(fun i (id,binder,s) ->
112
Hashtbl.find ids_to_inner_sorts (Cic2acic.source_id_of_id id)
115
("id",id)::("sort",sort)::
117
Names.Anonymous -> assert false
118
| Names.Name b -> ["binder",Names.string_of_id b]
120
[< X.xml_nempty "def" attrs (aux s) ; i >]
122
X.xml_nempty "target" [] (aux t)
125
let sort = Hashtbl.find ids_to_inner_sorts id in
126
X.xml_nempty "APPLY" ["id",id ; "sort",sort]
127
[< (List.fold_left (fun i x -> [< i ; (aux x) >]) [<>] li)
129
| A.AConst (id,subst,uri) ->
130
let sort = Hashtbl.find ids_to_inner_sorts id in
131
let attrs = ["uri", uri ; "id",id ; "sort",sort] in
132
aux_subst (X.xml_empty "CONST" attrs) subst
133
| A.AInd (id,subst,uri,i) ->
134
let attrs = ["uri", uri ; "noType",(string_of_int i) ; "id",id] in
135
aux_subst (X.xml_empty "MUTIND" attrs) subst
136
| A.AConstruct (id,subst,uri,i,j) ->
137
let sort = Hashtbl.find ids_to_inner_sorts id in
140
"noType",(string_of_int i) ; "noConstr",(string_of_int j) ;
141
"id",id ; "sort",sort]
143
aux_subst (X.xml_empty "MUTCONSTRUCT" attrs) subst
144
| A.ACase (id,uri,typeno,ty,te,patterns) ->
145
let sort = Hashtbl.find ids_to_inner_sorts id in
146
X.xml_nempty "MUTCASE"
148
"noType", (string_of_int typeno) ;
149
"id", id ; "sort",sort]
150
[< X.xml_nempty "patternsType" [] [< (aux ty) >] ;
151
X.xml_nempty "inductiveTerm" [] [< (aux te) >] ;
153
(fun i x -> [< i ; X.xml_nempty "pattern" [] [< aux x >] >])
156
| A.AFix (id, no, funs) ->
157
let sort = Hashtbl.find ids_to_inner_sorts id in
159
["noFun", (string_of_int no) ; "id",id ; "sort",sort]
161
(fun i (id,fi,ai,ti,bi) ->
163
X.xml_nempty "FixFunction"
164
["id",id ; "name", (Names.string_of_id fi) ;
165
"recIndex", (string_of_int ai)]
166
[< X.xml_nempty "type" [] [< aux ti >] ;
167
X.xml_nempty "body" [] [< aux bi >]
172
| A.ACoFix (id,no,funs) ->
173
let sort = Hashtbl.find ids_to_inner_sorts id in
175
["noFun", (string_of_int no) ; "id",id ; "sort",sort]
177
(fun i (id,fi,ti,bi) ->
179
X.xml_nempty "CofixFunction"
180
["id",id ; "name", Names.string_of_id fi]
181
[< X.xml_nempty "type" [] [< aux ti >] ;
182
X.xml_nempty "body" [] [< aux bi >]
187
and aux_subst target (id,subst) =
191
Xml.xml_nempty "instantiate"
192
(match id with None -> [] | Some id -> ["id",id])
196
[< i ; Xml.xml_nempty "arg" ["relUri", uri] (aux arg) >]
203
let param_attribute_of_params params =
207
(fun x i ->path ^ "/" ^ x ^ ".var" ^ match i with "" -> "" | i' -> " " ^ i'
208
) l "" ^ match i with "" -> "" | i' -> " " ^ i'
212
let print_object uri ids_to_inner_sorts =
214
let module A = Acic in
215
let module X = Xml in
217
A.ACurrentProof (id,n,conjectures,bo,ty) ->
218
let xml_for_current_proof_body =
219
(*CSC: Should the CurrentProof also have the list of variables it depends on? *)
220
(*CSC: I think so. Not implemented yet. *)
221
X.xml_nempty "CurrentProof" ["of",uri ; "id", id]
223
(fun i (cid,n,canonical_context,t) ->
225
X.xml_nempty "Conjecture"
226
["id", cid ; "no",export_existential n]
232
["id",hid;"name",Names.string_of_id n]
233
(print_term ids_to_inner_sorts t)
236
["id",hid;"name",Names.string_of_id n]
237
(print_term ids_to_inner_sorts t)
241
) [< >] canonical_context ;
242
X.xml_nempty "Goal" []
243
(print_term ids_to_inner_sorts t)
246
[<>] (List.rev conjectures) ;
247
X.xml_nempty "body" [] (print_term ids_to_inner_sorts bo) >]
249
let xml_for_current_proof_type =
250
X.xml_nempty "ConstantType" ["name",n ; "id", id]
251
(print_term ids_to_inner_sorts ty)
254
[< X.xml_cdata "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n" ;
255
X.xml_cdata ("<!DOCTYPE CurrentProof SYSTEM \""^dtdname ^"\">\n");
256
xml_for_current_proof_body
259
[< X.xml_cdata "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n" ;
261
("<!DOCTYPE ConstantType SYSTEM \"" ^ dtdname ^ "\">\n");
262
xml_for_current_proof_type
266
| A.AConstant (id,n,bo,ty,params) ->
267
let params' = param_attribute_of_params params in
274
"<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n" ;
276
("<!DOCTYPE ConstantBody SYSTEM \"" ^ dtdname ^ "\">\n") ;
277
X.xml_nempty "ConstantBody"
278
["for",uri ; "params",params' ; "id", id]
279
[< print_term ids_to_inner_sorts bo >]
283
[< X.xml_cdata "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n" ;
284
X.xml_cdata ("<!DOCTYPE ConstantType SYSTEM \""^dtdname ^"\">\n");
285
X.xml_nempty "ConstantType"
286
["name",n ; "params",params' ; "id", id]
287
[< print_term ids_to_inner_sorts ty >]
291
| A.AVariable (id,n,bo,ty,params) ->
292
let params' = param_attribute_of_params params in
293
[< X.xml_cdata "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n" ;
294
X.xml_cdata ("<!DOCTYPE Variable SYSTEM \"" ^ dtdname ^ "\">\n") ;
295
X.xml_nempty "Variable" ["name",n ; "params",params' ; "id", id]
299
X.xml_nempty "body" []
300
(print_term ids_to_inner_sorts bo)
302
X.xml_nempty "type" [] (print_term ids_to_inner_sorts ty)
305
| A.AInductiveDefinition (id,tys,params,nparams) ->
306
let params' = param_attribute_of_params params in
307
[< X.xml_cdata "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n" ;
308
X.xml_cdata ("<!DOCTYPE InductiveDefinition SYSTEM \"" ^
310
X.xml_nempty "InductiveDefinition"
311
["noParams",string_of_int nparams ;
315
(fun i (id,typename,finite,arity,cons) ->
317
X.xml_nempty "InductiveType"
318
["id",id ; "name",Names.string_of_id typename ;
319
"inductive",(string_of_bool finite)
321
[< X.xml_nempty "arity" []
322
(print_term ids_to_inner_sorts arity) ;
326
X.xml_nempty "Constructor"
327
["name",Names.string_of_id name]
328
(print_term ids_to_inner_sorts lc)
341
let print_inner_types curi ids_to_inner_sorts ids_to_inner_types =
342
let module C2A = Cic2acic in
343
let module X = Xml in
344
[< X.xml_cdata "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n" ;
345
X.xml_cdata ("<!DOCTYPE InnerTypes SYSTEM \"" ^ typesdtdname ^"\">\n");
346
X.xml_nempty "InnerTypes" ["of",curi]
348
(fun id {C2A.annsynthesized = synty ; C2A.annexpected = expty} x ->
350
X.xml_nempty "TYPE" ["of",id]
351
[< X.xml_nempty "synthesized" []
352
(print_term ids_to_inner_sorts synty) ;
356
X.xml_nempty "expected" []
357
(print_term ids_to_inner_sorts expty')
360
) ids_to_inner_types [<>]