]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/software/helena/src/common/entity.ml
- new attributes system
[helm.git] / helm / software / helena / src / common / entity.ml
index 9915dd3c37b385ef42b6cebf992feebf228ddb34..c447190501854daee08e11455956be0ae1477105 100644 (file)
@@ -18,102 +18,61 @@ type id = string (* identifier *)
 
 type name = id * bool (* token, real? *)
 
-type names = name list
-
 type meta = Main     (* main object *)
           | InProp   (* inhabitant of a proposition *)
           | Progress (* uncompleted object *)
          | Private  (* private global definition *)
 
-type attr = Name of name              (* name *)
-          | Apix of int               (* additional position index *)
-         | Mark of int               (* node marker *)
-         | Meta of meta list         (* metaliguistic classification *) 
-         | Info of (string * string) (* metaliguistic annotation: language (defaults to "en-US"), text *)
+type node_attrs = {
+   n_name: name option; (* name *)
+   n_apix: int option;  (* additional position index *)
+   n_degr: int;         (* degree *)
+   n_real: bool;        (* real node? (not generated) *)
+}
 
-type attrs = attr list (* attributes *)
+type root_attrs = {
+   r_meta: meta list;                (* metaliguistic classification *) 
+   r_info: (string * string) option; (* metaliguistic annotation: language (defaults to "en-US"), text *)
+}
 
-type 'term bind = Abst of N.level * 'term (* declaration: level, domain *)
-                | Abbr of 'term           (* definition: body           *)
-               | Void                    (* exclusion                  *)
+type 'term bind = Abst of 'term (* declaration: domain *)
+                | Abbr of 'term (* definition: body    *)
+               | Void          (* exclusion           *)
 
-type 'term entity = attrs * uri * 'term bind (* attrs, name, binder *)
+type 'term entity = root_attrs * node_attrs * uri * 'term bind (* attrs,  uri, binder *)
 
 (* helpers ******************************************************************)
 
-let common f (a, u, _) = f a u
-
-let rec name err f = function
-   | Name (n, r) :: _ -> f n r
-   | _ :: tl          -> name err f tl
-   | []               -> err ()
-
-let names f map l a =
-   let rec aux f i a = function   
-      | []                -> f a
-      | Name (n, r) :: tl -> aux (map f i n r) false a tl
-      | _ :: tl           -> aux f i a tl
-   in
-   aux f true a l
-
-let rec get_name err f j = function
-   | []                          -> err ()
-   | Name (n, r) :: _ when j = 0 -> f n r
-   | Name _ :: tl                -> get_name err f (pred j) tl
-   | _ :: tl                     -> get_name err f j tl
-
-let rec get_names f = function
-   | []                -> f [] []
-   | Name _ as n :: tl ->
-      let f a ns = f a (n :: ns) in get_names f tl
-   | e :: tl           ->
-      let f a = f (e :: a) in get_names f tl
-
-let count_names a =
-   let rec aux k = function
-      | []           -> k
-      | Name _ :: tl -> aux (succ k) tl
-      | _ :: tl      -> aux k tl
-   in
-   aux 0 a
-
-let rec apix err f = function
-   | Apix i :: _ -> f i
-   | _ :: tl     -> apix err f tl
-   | []          -> err ()
-
-let rec mark err f = function
-   | Mark i :: _ -> f i
-   | _ :: tl     -> mark err f tl
-   | []          -> err ()
-
-let rec meta err f = function
-   | Meta ms :: _ -> f ms
-   | _ :: tl      -> meta err f tl
-   | []           -> err ()
-
-let rec info err f = function
-   | Info (lg, tx) :: _ -> f lg tx
-   | _ :: tl            -> info err f tl
-   | []                 -> err ()
-
-let resolve err f name a =
-   let rec aux i = function
-      | Name (n, true) :: _ when n = name -> f i
-      | _ :: tl                           -> aux (succ i) tl
-      | []                                -> err i
-   in
-   aux 0 a
-
-let rec rev_append_names ns = function
-   | []           -> ns
-   | Name n :: tl -> rev_append_names (n :: ns) tl
-   | _ :: tl      -> rev_append_names ns tl
+let node_attrs ?(real=true) ?apix ?name ?(degr=0) () = {
+   n_real = real; n_apix = apix; n_name = name; n_degr = degr;
+}
+
+let root_attrs ?(meta=[]) ?info () = {
+   r_meta = meta; r_info = info;
+}
+
+let empty_node = node_attrs ()
+
+let empty_root = root_attrs ()
+
+let common f (ra, na, u, _) = f ra na u
+
+let rec name err f a = match a.n_name with
+   | Some (n, r) -> f n r
+   | None        -> err ()
+
+let rec apix err f a = match a.n_apix with
+   | Some i -> f i
+   | None   -> err ()
+
+let rec info err f a = match a.r_info with
+   | Some (lg, tx) -> f lg tx
+   | None          -> err ()
 
 let xlate f xlate_term = function
-   | a, uri, Abst (n, t) ->
-      let f t = f (a, uri, Abst (n, t)) in xlate_term f t
-   | a, uri, Abbr t      ->
-      let f t = f (a, uri, Abbr t) in xlate_term f t
-   | _, _, Void          ->
+   | ra, na, uri, Abst t ->
+      let f t = f (ra, na, uri, Abst t) in xlate_term f t
+   | ra, na, uri, Abbr t ->
+      let f t = f (ra, na, uri, Abbr t) in xlate_term f t
+   | _, _, _, Void       ->
       assert false