]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/software/lambda-delta/toplevel/metaBrg.ml
- we updated some preambles to match that of nUri.ml
[helm.git] / helm / software / lambda-delta / toplevel / metaBrg.ml
diff --git a/helm/software/lambda-delta/toplevel/metaBrg.ml b/helm/software/lambda-delta/toplevel/metaBrg.ml
new file mode 100644 (file)
index 0000000..4ca8e5c
--- /dev/null
@@ -0,0 +1,64 @@
+(*
+    ||M||  This file is part of HELM, an Hypertextual, Electronic        
+    ||A||  Library of Mathematics, developed at the Computer Science     
+    ||T||  Department, University of Bologna, Italy.                     
+    ||I||                                                                
+    ||T||  HELM is free software; you can redistribute it and/or         
+    ||A||  modify it under the terms of the GNU General Public License   
+    \   /  version 2 or (at your option) any later version.              
+     \ /   This software is distributed as is, NO WARRANTY.              
+      V_______________________________________________________________ *)
+
+module B = Brg
+module M = Meta
+
+(* Internal functions *******************************************************)
+
+let map_fold_left f map1 map2 a l =
+   let f a = Cps.list_fold_left f map2 a l in
+   map1 f a 
+
+let map_args f t v = f (B.Appl (v, t))
+
+let map_pars f t (id, w) = f (B.Bind (id, B.Abst, w, t))
+
+let rec xlate_term f = function
+   | M.Sort s            -> 
+      let f h = f (B.Sort h) in
+      if s then f 0 else f 1
+   | M.LRef (l, i)       ->
+      f (B.LRef (l - i))
+   | M.GRef (_, uri, vs) ->
+      let f vs = map_fold_left f Cps.id map_args (B.GRef uri) vs in
+      Cps.list_rev_map f xlate_term vs
+   | M.Appl (v, t)       ->
+      let f v t = f (B.Appl (v, t)) in
+      let f v = xlate_term (f v) t in
+      xlate_term f v
+   | M.Abst (id, w, t)   ->
+      let f w t = f (B.Bind (id, B.Abst, w, t)) in
+      let f w = xlate_term (f w) t in
+      xlate_term f w
+
+let xlate_pars f (id, w) =
+   let f w = f (id, w) in
+   xlate_term f w
+
+let xlate_entry f = function
+   | _, pars, uri, u, None        ->
+      let f u = f (uri, B.Abst, u) in
+      let f pars = map_fold_left f xlate_term map_pars u pars in      
+      Cps.list_rev_map f xlate_pars pars
+   | _, pars, uri, u, Some (_, t) ->
+      let f u t = f (uri, B.Abbr, (B.Cast (u, t))) in
+      let f pars u = map_fold_left (f u) xlate_term map_pars t pars in      
+      let f pars = map_fold_left (f pars) xlate_term map_pars u pars in
+      Cps.list_rev_map f xlate_pars pars
+
+let xlate_item f = function
+   | None   -> f None
+   | Some e -> let f e = f (Some e) in xlate_entry f e
+
+(* Interface functions ******************************************************)
+
+let brg_of_meta = xlate_item