]> matita.cs.unibo.it Git - helm.git/blob - helm/software/helena/src/common/entity.ml
- we are moving from old (patched) management of sort inclusion
[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 = Layer
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;         (* additional position index *)
29    n_degr: int;         (* degree *)
30    n_sort: int;         (* sort *)
31 }
32
33 type root_attrs = {
34    r_meta: meta list;                (* metaliguistic classification *) 
35    r_info: (string * string) option; (* metaliguistic annotation: language (defaults to "en-US"), text *)
36 }
37
38 type 'term bind = Abst of 'term (* declaration: domain *)
39                 | Abbr of 'term (* definition: body    *)
40                 | Void          (* exclusion           *)
41
42 type 'term entity = root_attrs * node_attrs * uri * 'term bind (* attrs, uri, binder *)
43
44 (* helpers ******************************************************************)
45
46 let node_attrs ?(apix=0) ?name ?(degr=0) ?(sort=0) () = {
47    n_apix = apix; n_name = name; n_degr = degr; n_sort = sort
48 }
49
50 let root_attrs ?(meta=[]) ?info () = {
51    r_meta = meta; r_info = info;
52 }
53
54 let empty_node = node_attrs ()
55
56 let empty_root = root_attrs ()
57
58 let common f (ra, na, u, _) = f ra na u
59
60 let rec name err f a = match a.n_name with
61    | Some (n, r) -> f n r
62    | None        -> err ()
63
64 let rec info err f a = match a.r_info with
65    | Some (lg, tx) -> f lg tx
66    | None          -> err ()
67
68 let xlate f xlate_term = function
69    | ra, na, uri, Abst t ->
70       let f t = f (ra, na, uri, Abst t) in xlate_term f t
71    | ra, na, uri, Abbr t ->
72       let f t = f (ra, na, uri, Abbr t) in xlate_term f t
73    | _, _, _, Void       ->
74       assert false