]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/software/lambda-delta/toplevel/metaAut.ml
- we added some syntactic sugar in the text parser
[helm.git] / helm / software / lambda-delta / toplevel / metaAut.ml
index 767a44afb4c8b313c744f6976f366ac976771e76..d686c0f2c3e4abbe0476d3633eedd8b5787c0879 100644 (file)
@@ -1,71 +1,63 @@
-(* Copyright (C) 2000, HELM Team.
- * 
- * This file is part of HELM, an Hypertextual, Electronic
- * Library of Mathematics, developed at the Computer Science
- * Department, University of Bologna, Italy.
- * 
- * HELM is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- * 
- * HELM is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with HELM; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
- * MA  02111-1307, USA.
- * 
- * For details, see the HELM World-Wide-Web page,
- * http://cs.unibo.it/helm/.
- *)
-
-module H = Hashtbl
+(*
+    ||M||  This file is part of HELM, an Hypertextual, Electronic        
+    ||A||  Library of Mathematics, developed at the Computer Science     
+    ||T||  Department, University of Bologna, Italy.                     
+    ||I||                                                                
+    ||T||  HELM is free software; you can redistribute it and/or         
+    ||A||  modify it under the terms of the GNU General Public License   
+    \   /  version 2 or (at your option) any later version.              
+     \ /   This software is distributed as is, NO WARRANTY.              
+      V_______________________________________________________________ *)
+
 module U = NUri
+module H = U.UriHash
+module C = Cps
+module Y = Entity
 module M = Meta
 module A = Aut
 
-type qid = M.id * M.id list (* qualified identifier: name, qualifiers *)
-
-type environment = (qid, M.pars) H.t
+(* qualified identifier: uri, name, qualifiers *)
+type qid = M.uri * M.id * M.id list
 
 type context_node = qid option (* context node: None = root *)
 
 type status = {
-   henv: environment;        (* optimized global environment *)
    path: M.id list;          (* current section path *) 
-   hcnt: environment;        (* optimized context *)   
    node: context_node;       (* current context node *)
    nodes: context_node list; (* context node list *)
    line: int;                (* line number *)
-   explicit: bool            (* need explicit context root? *)
+   cover: string             (* initial segment of URI hierarchy *) 
 }
 
 type resolver = Local of int
               | Global of M.pars
 
-let hsize = 11 (* hash tables initial size *)
+let henv_size, hcnt_size = 7000, 4300 (* hash tables initial sizes *)
+
+let henv = H.create henv_size (* optimized global environment *)
+
+let hcnt = H.create hcnt_size (* optimized context *) 
 
 (* Internal functions *******************************************************)
 
-let initial_status size = {
-   path = []; node = None; nodes = []; line = 1; explicit = true;
-   henv = H.create size; hcnt = H.create size
+let initial_status cover =
+   H.clear henv; H.clear hcnt; {
+   path = []; node = None; nodes = []; line = 1; cover = cover;
 }
 
 let id_of_name (id, _, _) = id
 
-let uri_of_qid (id, path) =
-   let path = String.concat "/" path in
-   let str = Filename.concat path id in
-   U.uri_of_string ("ld:/" ^ str)
+let mk_qid st id path =
+   let uripath = if st.cover = "" then path else st.cover :: path in
+   let str = String.concat "/" uripath in
+   let str = Filename.concat str id in 
+   U.uri_of_string ("ld:/" ^ str ^ ".ld"), id, path
+
+let uri_of_qid (uri, _, _) = uri
 
 let complete_qid f st (id, is_local, qs) =
-   let f qs = f (id, qs) in
-   let f path = Cps.list_rev_append f path ~tail:qs in
+   let f qs = f (mk_qid st id qs) in
+   let f path = C.list_rev_append f path ~tail:qs in
    let rec skip f = function
       | phd :: ptl, qshd :: _ when phd = qshd -> f ptl
       | _ :: ptl, _ :: _                      -> skip f (ptl, qs)
@@ -73,17 +65,17 @@ let complete_qid f st (id, is_local, qs) =
    in
    if is_local then f st.path else skip f (st.path, qs)
 
-let relax_qid f (id, path) =
-   let f path = f (id, path) in
+let relax_qid f st (_, id, path) =
+   let f path = f (mk_qid st id path) in
    let f = function
-      | _ :: tl -> Cps.list_rev f tl
+      | _ :: tl -> C.list_rev f tl
       | []      -> assert false
    in
-   Cps.list_rev f path
+   C.list_rev f path
 
-let relax_opt_qid f = function
+let relax_opt_qid f st = function
    | None     -> f None
-   | Some qid -> let f qid = f (Some qid) in relax_qid f qid
+   | Some qid -> let f qid = f (Some qid) in relax_qid f st qid
 
 let resolve_lref f st l lenv id =
    let rec aux f i = function
@@ -101,29 +93,32 @@ let resolve_lref_strict f st l lenv id =
    resolve_lref f st l lenv id
 
 let resolve_gref f st qid =
-   try let args = H.find st.henv qid in f qid (Some args)
+   try let args = H.find henv (uri_of_qid qid) in f qid (Some args)
    with Not_found -> f qid None
 
 let resolve_gref_relaxed f st qid =
+(* this is not tail recursive *)
    let rec g qid = function
-      | None      -> relax_qid (resolve_gref g st) qid
+      | None      -> relax_qid (resolve_gref g st) st qid
       | Some args -> f qid args
    in
    resolve_gref g st qid
 
 let get_pars f st = function
    | None              -> f [] None
-   | Some name as node ->
-      try let pars = H.find st.hcnt name in f pars None
+   | Some qid as node ->
+      try let pars = H.find hcnt (uri_of_qid qid) in f pars None
       with Not_found -> f [] (Some node)
 
 let get_pars_relaxed f st =
+(* this is not tail recursive *)
    let rec g pars = function
       | None      -> f pars 
-      | Some node -> relax_opt_qid (get_pars g st) node
+      | Some node -> relax_opt_qid (get_pars g st) st node
    in
    get_pars g st st.node
 
+(* this is not tail recursive on the GRef branch *)
 let rec xlate_term f st lenv = function
    | A.Sort sort         -> 
       f (M.Sort sort)
@@ -143,10 +138,10 @@ let rec xlate_term f st lenv = function
         let map2 f (id, _) = resolve_lref_strict f st l lenv id in
          let f tail = 
            let f args = f (M.GRef (l, uri_of_qid qid, args)) in
-            let f defs = Cps.list_rev_map_append f map2 defs ~tail in
-           Cps.list_sub_strict f defs args
+            let f defs = C.list_rev_map_append f map2 defs ~tail in
+           C.list_sub_strict f defs args
         in   
-        Cps.list_map f map1 args
+        C.list_map f map1 args
       in
       let g qid = resolve_gref_relaxed g st qid in
       let f = function
@@ -155,26 +150,26 @@ let rec xlate_term f st lenv = function
       in
       resolve_lref f st l lenv (id_of_name name)
 
-let xlate_item f st = function
-   | A.Section (Some name)     ->
-      f {st with path = name :: st.path; nodes = st.node :: st.nodes} None
+let xlate_entity err f st = function
+   | A.Section (Some (_, name))     ->
+      err {st with path = name :: st.path; nodes = st.node :: st.nodes}
    | A.Section None            ->
       begin match st.path, st.nodes with
         | _ :: ptl, nhd :: ntl -> 
-           f {st with path = ptl; node = nhd; nodes = ntl} None
+           err {st with path = ptl; node = nhd; nodes = ntl}
          | _                    -> assert false
       end
    | A.Context None            ->
-      f {st with node = None} None
+      err {st with node = None}
    | A.Context (Some name)     ->
-      let f name = f {st with node = Some name} None in
+      let f name = err {st with node = Some name} in
       complete_qid f st name 
    | A.Block (name, w)         ->
       let f qid = 
          let f pars =
            let f ww = 
-              H.add st.hcnt qid ((name, ww) :: pars);
-              f {st with node = Some qid} None
+              H.add hcnt (uri_of_qid qid) ((name, ww) :: pars);
+              err {st with node = Some qid}
            in
             xlate_term f st pars w
         in
@@ -185,9 +180,11 @@ let xlate_item f st = function
       let f pars = 
          let f qid = 
             let f ww =
-              let entry = (st.line, pars, uri_of_qid qid, ww, None) in
-              H.add st.henv qid pars;
-              f {st with line = succ st.line} (Some entry)
+              H.add henv (uri_of_qid qid) pars;
+              let a = [Y.Mark st.line] in
+              let entry = pars, ww, None in
+              let entity = a, uri_of_qid qid, Y.Abst entry in
+              f {st with line = succ st.line} entity
            in
            xlate_term f st pars w
         in
@@ -198,9 +195,11 @@ let xlate_item f st = function
       let f pars = 
          let f qid = 
             let f ww vv = 
-              let entry = (st.line, pars, uri_of_qid qid, ww, Some (trans, vv)) in
-              H.add st.henv qid pars;
-              f {st with line = succ st.line} (Some entry)
+              H.add henv (uri_of_qid qid) pars;
+              let a = Y.Mark st.line :: if trans then [] else [Y.Priv] in 
+              let entry = pars, ww, Some vv in
+              let entity = a, uri_of_qid qid, Y.Abbr entry in
+              f {st with line = succ st.line} entity
            in
            let f ww = xlate_term (f ww) st pars v in
            xlate_term f st pars w
@@ -211,6 +210,7 @@ let xlate_item f st = function
 
 (* Interface functions ******************************************************)
 
-let initial_status = initial_status hsize
+let initial_status ?(cover="") () =
+   initial_status cover
 
-let meta_of_aut = xlate_item
+let meta_of_aut = xlate_entity