]> matita.cs.unibo.it Git - helm.git/blob - helm/ocaml/cic_annotations/cicAnnotation2Xml.ml
23c3a9b68446a3812f8682a7c2a0e96c78051ac4
[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 let get_ann ids_to_annotations =
33  CicXPath.get_annotation ids_to_annotations
34 ;;
35
36 let print_ann i2a id =
37  let module X = Xml in
38   let ann = get_ann i2a id in
39    match ann with
40       None -> [<>]
41     | Some ann -> (X.xml_nempty "Annotation" [None,"of", id] (X.xml_cdata ann))
42 ;;
43
44 (*CSC ottimizzazione: al posto di curi cdepth (vedi codice) *)
45 (* It takes in input a hash table mapping ids to annotations, an annotated 
46 term, and gives back a Xml.token Stream.t representing the .ann file *)
47 let print_term i2a =
48  let rec aux =
49   let module C = Cic in
50   let module X = Xml in
51   let module U = UriManager in
52     function
53        C.ARel (id,_,_,_) -> print_ann i2a id
54      | C.AMeta (id,_,_) -> print_ann i2a id
55      | C.ASort (id,_) -> print_ann i2a id
56      | C.AImplicit _ -> raise NotImplemented
57      | C.AProd (id,_,s,t) -> [< print_ann i2a id ; aux s ; aux t >]
58      | C.ACast (id,v,t) -> [< print_ann i2a id ; aux v ; aux t >]
59      | C.ALambda (id,_,s,t) -> [< print_ann i2a id ; aux s ; aux t >]
60      | C.ALetIn (id,_,s,t) -> [< print_ann i2a id ; aux s ; aux t >]
61      | C.AAppl (id,li) ->
62         [< print_ann i2a id ;
63            List.fold_right (fun x i -> [< (aux x) ; i >]) li [<>]
64         >]
65      | C.AVar (id,_,exp_named_subst)
66      | C.AConst (id,_,exp_named_subst)
67      | C.AMutInd (id,_,_,exp_named_subst)
68      | C.AMutConstruct (id,_,_,_,exp_named_subst) ->
69         [< print_ann i2a id ;
70            List.fold_right
71             (fun (_,x) i -> [< aux x ; i >])
72             exp_named_subst [<>]
73         >] 
74      | C.AMutCase (id,_,_,ty,te,patterns) ->
75         [< print_ann i2a id ;
76            aux ty ;
77            aux te ;
78            List.fold_right
79             (fun x i -> [< aux x ; i>])
80             patterns [<>]
81         >]
82      | C.AFix (id,_,funs) ->
83         [< print_ann i2a id ;
84            List.fold_right
85             (fun (_,_,_,ti,bi) i -> [< aux ti ; aux bi ; i >]) funs [<>]
86         >]
87      | C.ACoFix (id,no,funs) ->
88         [< print_ann i2a id ;
89            List.fold_right
90             (fun (_,_,ti,bi) i -> [< aux ti ; aux bi ; i >]) funs [<>]
91         >]
92  in
93   aux
94 ;;
95
96 let print_mutual_inductive_type i2a (_,_,_,arity,constructors) =
97  [< print_term i2a arity ;
98     List.fold_right
99      (fun (name,ty) i -> [< print_term i2a ty ; i >]) constructors [<>]
100  >]
101 ;;
102
103 let pp_annotation obj i2a curi =
104  let module C = Cic in
105  let module X = Xml in
106   [< X.xml_cdata "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n" ;
107      X.xml_cdata ("<!DOCTYPE Annotations SYSTEM \"" ^ dtdname ^ "\">\n\n") ;
108      X.xml_nempty "Annotations"
109       [None, "of", UriManager.string_of_uri (UriManager.cicuri_of_uri curi)]
110       begin
111        match obj with
112          C.AConstant (xid, xidobj, _, te, ty, _) ->
113           [< print_ann i2a xid ;
114              (match xidobj,te with
115                  Some xidobj, Some te ->
116                   [< print_ann i2a xidobj ;
117                      print_term i2a te
118                   >]
119                | None, None -> [<>]
120                | _,_ -> assert false
121              ) ;
122              print_term i2a ty
123           >]
124        | C.AVariable (xid, _, bo, ty,_) ->
125           [< print_ann i2a xid ;
126              (match bo with
127                  None -> [<>]
128                | Some bo -> print_term i2a bo
129              ) ;
130              print_term i2a ty
131           >]
132        | C.ACurrentProof (xid, xidobj, _, conjs, bo, ty,_) ->
133           [< print_ann i2a xid ;
134              print_ann i2a xidobj ;
135              List.fold_right
136               (fun (cid, _, context, t) i ->
137                 [< print_ann i2a cid ;
138                    List.fold_right
139                     (fun (hid,context_entry) i -> 
140                       [<print_ann i2a hid ;
141                         (match context_entry with
142                             Some (_,C.ADecl at) -> print_term i2a at
143                           | Some (_,C.ADef at) -> print_term i2a at
144                           | None -> [< >]
145                         ) ; i
146                        >]
147                     ) context [< >];
148                    print_term i2a t ; i
149                 >]
150               ) conjs [<>] ;
151              print_term i2a bo ;
152              print_term i2a ty
153           >]
154        | C.AInductiveDefinition (xid, tys, params, paramsno) ->
155           [< print_ann i2a xid ;
156              List.fold_right
157               (fun x i -> [< print_mutual_inductive_type i2a x ; i >])
158               tys [< >]
159           >]
160       end
161   >]
162 ;;
163
164
165