]> matita.cs.unibo.it Git - helm.git/blob - helm/software/helena/src/common/entity.ml
- the disambiguation of unified binders continues
[helm.git] / helm / software / helena / src / 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 module U = NUri
13 module N = Level
14
15 type uri = U.uri
16
17 type id = string (* identifier *)
18
19 type name = id * bool (* token, real? *)
20
21 type meta = Main     (* main object *)
22           | InProp   (* inhabitant of a proposition *)
23           | Progress (* uncompleted object *)
24           | Private  (* private global definition *)
25
26 type node_attrs = {
27    n_name: name option; (* name *)
28    n_apix: int option;  (* additional position index *)
29    n_degr: int;         (* degree *)
30 }
31
32 type root_attrs = {
33    r_meta: meta list;                (* metaliguistic classification *) 
34    r_info: (string * string) option; (* metaliguistic annotation: language (defaults to "en-US"), text *)
35 }
36
37 type 'term bind = Abst of 'term (* declaration: domain *)
38                 | Abbr of 'term (* definition: body    *)
39                 | Void          (* exclusion           *)
40
41 type 'term entity = root_attrs * node_attrs * uri * 'term bind (* attrs, uri, binder *)
42
43 (* helpers ******************************************************************)
44
45 let node_attrs ?(real=true) ?apix ?name ?(degr=0) () = {
46    n_apix = apix; n_name = name; n_degr = degr;
47 }
48
49 let root_attrs ?(meta=[]) ?info () = {
50    r_meta = meta; r_info = info;
51 }
52
53 let empty_node = node_attrs ()
54
55 let empty_root = root_attrs ()
56
57 let common f (ra, na, u, _) = f ra na u
58
59 let rec name err f a = match a.n_name with
60    | Some (n, r) -> f n r
61    | None        -> err ()
62
63 let rec apix err f a = match a.n_apix with
64    | Some i -> f i
65    | None   -> err ()
66
67 let rec info err f a = match a.r_info with
68    | Some (lg, tx) -> f lg tx
69    | None          -> err ()
70
71 let xlate f xlate_term = function
72    | ra, na, uri, Abst t ->
73       let f t = f (ra, na, uri, Abst t) in xlate_term f t
74    | ra, na, uri, Abbr t ->
75       let f t = f (ra, na, uri, Abbr t) in xlate_term f t
76    | _, _, _, Void       ->
77       assert false