(* ||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 C = Cps module Y = Entity module B = Brg module M = Meta (* Internal functions *******************************************************) let rec xlate_term c f = function | M.Sort s -> let f h = f (B.Sort ([], h)) in if s then f 0 else f 1 | M.LRef (_, i) -> f (B.LRef ([], i)) | M.GRef (_, uri, 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 c (f v) t in xlate_term c f v | M.Abst (id, w, t) -> let f w = let a = [Y.Name (id, true)] in let f t = f (B.Bind (a, B.Abst w, t)) in xlate_term (B.push c B.empty a (B.Abst w)) f t in xlate_term c f w let xlate_pars f pars = let map f (id, w) c = let a = [Y.Name (id, true)] in let f w = f (B.push c B.empty a (B.Abst w)) in xlate_term c f w in C.list_fold_right f map pars B.empty let unwind_to_xlate_term f c t = let map t a b = B.bind a b t in let f t = f (B.fold_left map t c) in xlate_term c f t let xlate_entry f = function | pars, u, None -> let f c = unwind_to_xlate_term f c u in xlate_pars f pars | pars, u, Some t -> let f u t = f (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 (* Interface functions ******************************************************) let brg_of_meta = xlate_entry