]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/interface/annotation2Xml.ml
Initial revision
[helm.git] / helm / interface / annotation2Xml.ml
diff --git a/helm/interface/annotation2Xml.ml b/helm/interface/annotation2Xml.ml
new file mode 100644 (file)
index 0000000..a9fca07
--- /dev/null
@@ -0,0 +1,190 @@
+(*CSC codice cut & paste da cicPp e xmlcommand *)
+
+exception ImpossiblePossible;;
+exception NotImplemented;;
+exception BinderNotSpecified;;
+
+let dtdname = "http://localhost:8081/getdtd?url=annotations.dtd";;
+
+(*CSC ottimizzazione: al posto di curi cdepth (vedi codice) *)
+let print_term =
+ let rec aux =
+  let module C = Cic in
+  let module X = Xml in
+  let module U = UriManager in
+    function
+       C.ARel (id,ann,_,_) ->
+        (match !ann with
+            None -> [<>]
+          | Some ann -> (X.xml_nempty "Annotation" ["of", id] (X.xml_cdata ann))
+        )
+     | C.AVar (id,ann,_) ->
+        (match !ann with
+            None -> [<>]
+          | Some ann -> (X.xml_nempty "Annotation" ["of", id] (X.xml_cdata ann))
+        )
+     | C.AMeta (id,ann,_) ->
+        (match !ann with
+            None -> [<>]
+          | Some ann -> (X.xml_nempty "Annotation" ["of", id] (X.xml_cdata ann))
+        )
+     | C.ASort (id,ann,_) ->
+        (match !ann with
+            None -> [<>]
+          | Some ann -> (X.xml_nempty "Annotation" ["of", id] (X.xml_cdata ann))
+        )
+     | C.AImplicit _ -> raise NotImplemented
+     | C.AProd (id,ann,_,s,t) ->
+        [< (match !ann with
+               None -> [<>]
+             | Some ann ->
+                (X.xml_nempty "Annotation" ["of", id] (X.xml_cdata ann))
+           ) ;
+           aux s ;
+           aux t
+        >]
+     | C.ACast (id,ann,v,t) ->
+        [< (match !ann with
+               None -> [<>]
+             | Some ann ->
+                (X.xml_nempty "Annotation" ["of", id] (X.xml_cdata ann))
+           ) ;
+           aux v ;
+           aux t
+        >]
+     | C.ALambda (id,ann,_,s,t) ->
+        [< (match !ann with
+               None -> [<>]
+             | Some ann ->
+                (X.xml_nempty "Annotation" ["of", id] (X.xml_cdata ann))
+           ) ;
+           aux s ;
+           aux t
+        >]
+     | C.AAppl (id,ann,li) ->
+        [< (match !ann with
+               None -> [<>]
+             | Some ann ->
+                (X.xml_nempty "Annotation" ["of", id] (X.xml_cdata ann))
+           ) ;
+           List.fold_right (fun x i -> [< (aux x) ; i >]) li [<>]
+        >]
+     | C.AConst (id,ann,_,_) ->
+        (match !ann with
+            None -> [<>]
+          | Some ann -> (X.xml_nempty "Annotation" ["of", id] (X.xml_cdata ann))
+        )
+     | C.AAbst (id,ann,_) -> raise NotImplemented
+     | C.AMutInd (id,ann,_,_,_) ->
+        (match !ann with
+            None -> [<>]
+          | Some ann -> (X.xml_nempty "Annotation" ["of", id] (X.xml_cdata ann))
+        )
+     | C.AMutConstruct (id,ann,_,_,_,_) ->
+        (match !ann with
+            None -> [<>]
+          | Some ann -> (X.xml_nempty "Annotation" ["of", id] (X.xml_cdata ann))
+        )
+     | C.AMutCase (id,ann,_,_,_,ty,te,patterns) ->
+        [< (match !ann with
+               None -> [<>]
+             | Some ann ->
+                (X.xml_nempty "Annotation" ["of", id] (X.xml_cdata ann))
+           ) ;
+           aux ty ;
+           aux te ;
+           List.fold_right
+            (fun x i -> [< aux x ; i>])
+            patterns [<>]
+        >]
+     | C.AFix (id, ann, _, funs) ->
+        [< (match !ann with
+               None -> [<>]
+             | Some ann ->
+                (X.xml_nempty "Annotation" ["of", id] (X.xml_cdata ann))
+           ) ;
+           List.fold_right
+            (fun (_,_,ti,bi) i -> [< aux ti ; aux bi ; i >]) funs [<>]
+        >]
+     | C.ACoFix (id, ann,no,funs) ->
+        [< (match !ann with
+               None -> [<>]
+             | Some ann ->
+                (X.xml_nempty "Annotation" ["of", id] (X.xml_cdata ann))
+           ) ;
+           List.fold_right
+            (fun (_,ti,bi) i -> [< aux ti ; aux bi ; i >]) funs [<>]
+        >]
+ in
+  aux
+;;
+
+let print_mutual_inductive_type (_,_,arity,constructors) =
+ [< print_term arity ;
+    List.fold_right
+     (fun (name,ty,_) i -> [< print_term ty ; i >]) constructors [<>]
+ >]
+;;
+
+let target_uri_of_annotation_uri uri =
+ Str.replace_first (Str.regexp "\.ann$") "" (UriManager.string_of_uri uri)
+;;
+
+let pp_annotation obj curi =
+ let module C = Cic in
+ let module X = Xml in
+  [< X.xml_cdata "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n" ;
+     X.xml_cdata ("<!DOCTYPE Annotations SYSTEM \"" ^ dtdname ^ "\">\n\n") ;
+     X.xml_nempty "Annotations" ["of", target_uri_of_annotation_uri curi]
+      begin
+       match obj with
+         C.ADefinition (xid, ann, _, te, ty, _) ->
+          [< (match !ann with
+                 None -> [<>]
+               | Some ann ->
+                  X.xml_nempty "Annotation" ["of", xid] (X.xml_cdata ann)
+             ) ;
+             print_term te ;
+             print_term ty
+          >]
+       | C.AAxiom (xid, ann, _, ty, _) ->
+          [< (match !ann with
+                 None -> [<>]
+               | Some ann ->
+                  X.xml_nempty "Annotation" ["of", xid] (X.xml_cdata ann)
+             ) ;
+             print_term ty
+          >]
+       | C.AVariable (xid, ann, _, ty) ->
+          [< (match !ann with
+                 None -> [<>]
+               | Some ann ->
+                  X.xml_nempty "Annotation" ["of", xid] (X.xml_cdata ann)
+             ) ;
+             print_term ty
+          >]
+       | C.ACurrentProof (xid, ann, _, conjs, bo, ty) ->
+          [< (match !ann with
+                 None -> [<>]
+               | Some ann ->
+                  X.xml_nempty "Annotation" ["of", xid] (X.xml_cdata ann)
+             ) ;
+             List.fold_right
+              (fun (_,t) i -> [< print_term t ; i >])
+              conjs [<>] ;
+             print_term bo ;
+             print_term ty
+          >]
+       | C.AInductiveDefinition (xid, ann, tys, params, paramsno) ->
+          [< (match !ann with
+                 None -> [<>]
+               | Some ann ->
+                  X.xml_nempty "Annotation" ["of", xid] (X.xml_cdata ann)
+             ) ;
+             List.fold_right
+              (fun x i -> [< print_mutual_inductive_type x ; i >])
+              tys [< >]
+          >]
+      end
+  >]
+;;