]> matita.cs.unibo.it Git - helm.git/blob - helm/ocaml/cic_annotations/cicAnnotation2Xml.ml
* .mli added where needed
[helm.git] / helm / ocaml / cic_annotations / cicAnnotation2Xml.ml
1 (* Copyright (C) 2000, HELM Team.
2  * 
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.
6  * 
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.
11  * 
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.
16  *
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,
20  * MA  02111-1307, USA.
21  * 
22  * For details, see the HELM World-Wide-Web page,
23  * http://cs.unibo.it/helm/.
24  *)
25
26 (*CSC codice cut & paste da cicPp e xmlcommand *)
27
28 exception NotImplemented;;
29
30 let dtdname = "http://www.cs.unibo.it/helm/dtd/annotations.dtd";;
31
32 (*CSC ottimizzazione: al posto di curi cdepth (vedi codice) *)
33 let print_term =
34  let rec aux =
35   let module C = Cic in
36   let module X = Xml in
37   let module U = UriManager in
38     function
39        C.ARel (id,ann,_,_) ->
40         (match !ann with
41             None -> [<>]
42           | Some ann -> (X.xml_nempty "Annotation" ["of", id] (X.xml_cdata ann))
43         )
44      | C.AVar (id,ann,_) ->
45         (match !ann with
46             None -> [<>]
47           | Some ann -> (X.xml_nempty "Annotation" ["of", id] (X.xml_cdata ann))
48         )
49      | C.AMeta (id,ann,_) ->
50         (match !ann with
51             None -> [<>]
52           | Some ann -> (X.xml_nempty "Annotation" ["of", id] (X.xml_cdata ann))
53         )
54      | C.ASort (id,ann,_) ->
55         (match !ann with
56             None -> [<>]
57           | Some ann -> (X.xml_nempty "Annotation" ["of", id] (X.xml_cdata ann))
58         )
59      | C.AImplicit _ -> raise NotImplemented
60      | C.AProd (id,ann,_,s,t) ->
61         [< (match !ann with
62                None -> [<>]
63              | Some ann ->
64                 (X.xml_nempty "Annotation" ["of", id] (X.xml_cdata ann))
65            ) ;
66            aux s ;
67            aux t
68         >]
69      | C.ACast (id,ann,v,t) ->
70         [< (match !ann with
71                None -> [<>]
72              | Some ann ->
73                 (X.xml_nempty "Annotation" ["of", id] (X.xml_cdata ann))
74            ) ;
75            aux v ;
76            aux t
77         >]
78      | C.ALambda (id,ann,_,s,t) ->
79         [< (match !ann with
80                None -> [<>]
81              | Some ann ->
82                 (X.xml_nempty "Annotation" ["of", id] (X.xml_cdata ann))
83            ) ;
84            aux s ;
85            aux t
86         >]
87      | C.ALetIn (id,ann,_,s,t) ->
88         [< (match !ann with
89                None -> [<>]
90              | Some ann ->
91                 (X.xml_nempty "Annotation" ["of", id] (X.xml_cdata ann))
92            ) ;
93            aux s ;
94            aux t
95         >]
96      | C.AAppl (id,ann,li) ->
97         [< (match !ann with
98                None -> [<>]
99              | Some ann ->
100                 (X.xml_nempty "Annotation" ["of", id] (X.xml_cdata ann))
101            ) ;
102            List.fold_right (fun x i -> [< (aux x) ; i >]) li [<>]
103         >]
104      | C.AConst (id,ann,_,_) ->
105         (match !ann with
106             None -> [<>]
107           | Some ann -> (X.xml_nempty "Annotation" ["of", id] (X.xml_cdata ann))
108         )
109      | C.AAbst (id,ann,_) -> raise NotImplemented
110      | C.AMutInd (id,ann,_,_,_) ->
111         (match !ann with
112             None -> [<>]
113           | Some ann -> (X.xml_nempty "Annotation" ["of", id] (X.xml_cdata ann))
114         )
115      | C.AMutConstruct (id,ann,_,_,_,_) ->
116         (match !ann with
117             None -> [<>]
118           | Some ann -> (X.xml_nempty "Annotation" ["of", id] (X.xml_cdata ann))
119         )
120      | C.AMutCase (id,ann,_,_,_,ty,te,patterns) ->
121         [< (match !ann with
122                None -> [<>]
123              | Some ann ->
124                 (X.xml_nempty "Annotation" ["of", id] (X.xml_cdata ann))
125            ) ;
126            aux ty ;
127            aux te ;
128            List.fold_right
129             (fun x i -> [< aux x ; i>])
130             patterns [<>]
131         >]
132      | C.AFix (id, ann, _, funs) ->
133         [< (match !ann with
134                None -> [<>]
135              | Some ann ->
136                 (X.xml_nempty "Annotation" ["of", id] (X.xml_cdata ann))
137            ) ;
138            List.fold_right
139             (fun (_,_,ti,bi) i -> [< aux ti ; aux bi ; i >]) funs [<>]
140         >]
141      | C.ACoFix (id, ann,no,funs) ->
142         [< (match !ann with
143                None -> [<>]
144              | Some ann ->
145                 (X.xml_nempty "Annotation" ["of", id] (X.xml_cdata ann))
146            ) ;
147            List.fold_right
148             (fun (_,ti,bi) i -> [< aux ti ; aux bi ; i >]) funs [<>]
149         >]
150  in
151   aux
152 ;;
153
154 let print_mutual_inductive_type (_,_,arity,constructors) =
155  [< print_term arity ;
156     List.fold_right
157      (fun (name,ty,_) i -> [< print_term ty ; i >]) constructors [<>]
158  >]
159 ;;
160
161 let pp_annotation obj curi =
162  let module C = Cic in
163  let module X = Xml in
164   [< X.xml_cdata "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n" ;
165      X.xml_cdata ("<!DOCTYPE Annotations SYSTEM \"" ^ dtdname ^ "\">\n\n") ;
166      X.xml_nempty "Annotations"
167       ["of", UriManager.string_of_uri (UriManager.cicuri_of_uri curi)]
168       begin
169        match obj with
170          C.ADefinition (xid, ann, _, te, ty, _) ->
171           [< (match !ann with
172                  None -> [<>]
173                | Some ann ->
174                   X.xml_nempty "Annotation" ["of", xid] (X.xml_cdata ann)
175              ) ;
176              print_term te ;
177              print_term ty
178           >]
179        | C.AAxiom (xid, ann, _, ty, _) ->
180           [< (match !ann with
181                  None -> [<>]
182                | Some ann ->
183                   X.xml_nempty "Annotation" ["of", xid] (X.xml_cdata ann)
184              ) ;
185              print_term ty
186           >]
187        | C.AVariable (xid, ann, _, bo, ty) ->
188           [< (match !ann with
189                  None -> [<>]
190                | Some ann ->
191                   X.xml_nempty "Annotation" ["of", xid] (X.xml_cdata ann)
192              ) ;
193              (match bo with
194                  None -> [<>]
195                | Some bo -> print_term bo
196              ) ;
197              print_term ty
198           >]
199        | C.ACurrentProof (xid, ann, _, conjs, bo, ty) ->
200           [< (match !ann with
201                  None -> [<>]
202                | Some ann ->
203                   X.xml_nempty "Annotation" ["of", xid] (X.xml_cdata ann)
204              ) ;
205              List.fold_right
206               (fun (_,t) i -> [< print_term t ; i >])
207               conjs [<>] ;
208              print_term bo ;
209              print_term ty
210           >]
211        | C.AInductiveDefinition (xid, ann, tys, params, paramsno) ->
212           [< (match !ann with
213                  None -> [<>]
214                | Some ann ->
215                   X.xml_nempty "Annotation" ["of", xid] (X.xml_cdata ann)
216              ) ;
217              List.fold_right
218               (fun x i -> [< print_mutual_inductive_type x ; i >])
219               tys [< >]
220           >]
221       end
222   >]
223 ;;