]> matita.cs.unibo.it Git - helm.git/blob - helm/software/lambda-delta/common/entity.ml
- common/entity: new format for kernel entities
[helm.git] / helm / software / lambda-delta / common / entity.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 type uri = NUri.uri
13 type id = Aut.id
14
15 type attr = Name of id * bool (* name, real? *)
16           | Apix of int       (* additional position index *)
17           | Mark of int       (* node marker *)
18           | Priv              (* private global definition *)
19
20 type attrs = attr list (* attributes *)
21
22 type 'term bind = Abst of 'term (* declaration: domain *)
23                 | Abbr of 'term (* definition: body *)
24
25 type 'term entity = attrs * uri * 'term bind (* attrs, name, binder *)
26
27 type 'a uri_generator = (string -> 'a) -> string -> 'a 
28
29 (* helpers ******************************************************************)
30
31 let rec name err f = function
32    | Name (n, r) :: _ -> f n r
33    | _ :: tl          -> name err f tl
34    | []               -> err ()
35
36 let rec apix err f = function
37    | Apix i :: _ -> f i
38    | _ :: tl     -> apix err f tl
39    | []          -> err ()
40
41 let rec mark err f = function
42    | Mark i :: _ -> f i
43    | _ :: tl     -> mark err f tl
44    | []          -> err ()
45
46 let rec priv err f = function
47    | Priv :: _ -> f ()
48    | _ :: tl   -> priv err f tl
49    | []        -> err ()
50
51 let resolve err f name a =
52    let rec aux i = function
53       | Name (n, true) :: _ when n = name -> f i
54       | _ :: tl                           -> aux (succ i) tl
55       | []                                -> err i
56    in
57    aux 0 a
58
59 let xlate f xlate_term = function
60    | a, uri, Abst t ->
61       let f t = f (a, uri, Abst t) in xlate_term f t
62    | a, uri, Abbr t ->
63       let f t = f (a, uri, Abbr t) in xlate_term f t