]> matita.cs.unibo.it Git - helm.git/blob - helm/software/lambda-delta/common/entity.ml
Additional contribs.
[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                 | Void          (* exclusion *)
25
26 type 'term entity = attrs * uri * 'term bind (* attrs, name, binder *)
27
28 type uri_generator = string -> string
29
30 type status = {
31    delta: bool; (* global delta-expansion *)
32    rt: bool;    (* reference typing *)
33    si: bool     (* sort inclusion *)
34 }
35
36 (* helpers ******************************************************************)
37
38 let common f (a, u, _) = f a u
39
40 let rec name err f = function
41    | Name (n, r) :: _ -> f n r
42    | _ :: tl          -> name err f tl
43    | []               -> err ()
44
45 let names f map l a =
46    let rec aux f i a = function   
47       | []                -> f a
48       | Name (n, r) :: tl -> aux (map f i n r) false a tl
49       | _ :: tl           -> aux f i a tl
50    in
51    aux f true a l
52
53 let rec get_name err f j = function
54    | []                          -> err ()
55    | Name (n, r) :: _ when j = 0 -> f n r
56    | Name _ :: tl                -> get_name err f (pred j) tl
57    | _ :: tl                     -> get_name err f j tl
58
59 let rec get_names f = function
60    | []                -> f [] []
61    | Name _ as n :: tl ->
62       let f a ns = f a (n :: ns) in get_names f tl
63    | e :: tl           ->
64       let f a = f (e :: a) in get_names f tl
65
66 let rec apix err f = function
67    | Apix i :: _ -> f i
68    | _ :: tl     -> apix err f tl
69    | []          -> err ()
70
71 let rec mark err f = function
72    | Mark i :: _ -> f i
73    | _ :: tl     -> mark err f tl
74    | []          -> err ()
75
76 let rec priv err f = function
77    | Priv :: _ -> f ()
78    | _ :: tl   -> priv err f tl
79    | []        -> err ()
80
81 let resolve err f name a =
82    let rec aux i = function
83       | Name (n, true) :: _ when n = name -> f i
84       | _ :: tl                           -> aux (succ i) tl
85       | []                                -> err i
86    in
87    aux 0 a
88
89 let xlate f xlate_term = function
90    | a, uri, Abst t ->
91       let f t = f (a, uri, Abst t) in xlate_term f t
92    | a, uri, Abbr t ->
93       let f t = f (a, uri, Abbr t) in xlate_term f t
94    | _, _, Void   ->
95       assert false
96
97 let initial_status si = {
98    delta = false; rt = false; si = si
99 }