]> matita.cs.unibo.it Git - helm.git/blob - helm/software/lambda-delta/toplevel/metaBrg.ml
dfc7e8b56379ae8199bf3a58c87169c53f518435
[helm.git] / helm / software / lambda-delta / toplevel / metaBrg.ml
1 (*
2     ||M||  This file is part of HELM, an Hypertextual, Electronic        
3     ||A||  Library of Mathematics, developed at the Computer Science     
4     ||T||  Department, University of Bologna, Italy.                     
5     ||I||                                                                
6     ||T||  HELM is free software; you can redistribute it and/or         
7     ||A||  modify it under the terms of the GNU General Public License   
8     \   /  version 2 or (at your option) any later version.              
9      \ /   This software is distributed as is, NO WARRANTY.              
10       V_______________________________________________________________ *)
11
12 module C = Cps
13 module B = Brg
14 module M = Meta
15
16 (* Internal functions *******************************************************)
17
18 let map_fold_left f map1 map2 a l =
19    let f a = C.list_fold_left f map2 a l in
20    map1 f a 
21
22 let map_args f t v = f (B.Appl (v, t))
23
24 let map_pars f t (id, w) = f (B.Bind (id, B.Abst w, t))
25
26 let rec xlate_term f = function
27    | M.Sort s            -> 
28       let f h = f (B.Sort h) in
29       if s then f 0 else f 1
30    | M.LRef (l, i)       ->
31       f (B.LRef (l - succ i))
32    | M.GRef (_, uri, vs) ->
33       let f vs = map_fold_left f C.id map_args (B.GRef uri) vs in
34       C.list_map f xlate_term vs
35    | M.Appl (v, t)       ->
36       let f v t = f (B.Appl (v, t)) in
37       let f v = xlate_term (f v) t in
38       xlate_term f v
39    | M.Abst (id, w, t)   ->
40       let f w t = f (B.Bind (id, B.Abst w, t)) in
41       let f w = xlate_term (f w) t in
42       xlate_term f w
43
44 let xlate_pars f (id, w) =
45    let f w = f (id, w) in
46    xlate_term f w
47
48 let xlate_entry f = function
49    | e, pars, uri, u, None        ->
50       let f u = f (e, uri, B.Abst u) in
51       let f pars = map_fold_left f xlate_term map_pars u pars in      
52       C.list_map f xlate_pars pars
53    | e, pars, uri, u, Some (_, t) ->
54       let f u t = f (e, uri, B.Abbr (B.Cast (u, t))) in
55       let f pars u = map_fold_left (f u) xlate_term map_pars t pars in      
56       let f pars = map_fold_left (f pars) xlate_term map_pars u pars in
57       C.list_map f xlate_pars pars
58
59 let xlate_item f = function
60    | None   -> f None
61    | Some e -> let f e = f (Some e) in xlate_entry f e
62
63 (* Interface functions ******************************************************)
64
65 let brg_of_meta = xlate_item