]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/software/lambda-delta/toplevel/metaBrg.ml
basic_rg: bugfix in AST to allow attributes in global entries
[helm.git] / helm / software / lambda-delta / toplevel / metaBrg.ml
index 7c7adce7e73bbb41c63a6133751030313183d05a..4c5696ceaf86802c60dd60e508f2c021f1032c0b 100644 (file)
@@ -9,51 +9,58 @@
      \ /   This software is distributed as is, NO WARRANTY.              
       V_______________________________________________________________ *)
 
+module C = Cps
 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
+let rec xlate_term c f = function
    | M.Sort s            -> 
-      let f h = f (B.Sort h) in
+      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.LRef (_, i)       ->
+      f (B.LRef ([], 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
+      let map f t v = f (B.appl [] v t) in
+      let f vs = C.list_fold_left f map (B.GRef ([], uri)) vs in
+      C.list_map f (xlate_term c) 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
+      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 f w = 
+         let a = [B.Name (true, id)] in
+        let f t = f (B.Bind (B.abst a w, t)) in
+         let f c = xlate_term c f t in
+         B.push f c (B.abst a w)
+      in
+      xlate_term c f w
+
+let xlate_pars f pars =
+   let map f (id, w) c =
+      let a = [B.Name (true, id)] in
+      let f w = B.push f c (B.abst a w) in
+      xlate_term c f w
+   in
+   C.list_fold_right f map pars B.empty_context
 
-let xlate_pars f (id, w) =
-   let f w = f (id, w) in
-   xlate_term f w
+let unwind_to_xlate_term f c t =
+   let map f t b = f (B.bind b t) in
+   let f t = B.fold_left f map t c in
+   xlate_term c f t
 
 let xlate_entry f = function
-   | _, pars, uri, u, None        ->
-      let f u = f ((B.Abst, u), uri) 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 ((B.Abbr, (B.Cast (u, t))), uri) 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
+   | e, pars, uri, u, None        ->
+      let f u = f (e, uri, B.abst [] u) in
+      let f c = unwind_to_xlate_term f c u in      
+      xlate_pars f pars   
+   | e, pars, uri, u, Some (_, t) ->
+      let f u t = f (e, uri, B.abbr [] (B.Cast ([], u, t))) in
+      let f c u = unwind_to_xlate_term (f u) c t in
+      let f c = unwind_to_xlate_term (f c) c u in
+      xlate_pars f pars
 
 let xlate_item f = function
    | None   -> f None