]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/software/lambda-delta/toplevel/metaAut.ml
we now do some static analysis on the Automath text to possibly clear some language...
[helm.git] / helm / software / lambda-delta / toplevel / metaAut.ml
index 59801dac7833fc98efe739589ef10bd23a9ebab5..48628b2bb489eea631a6c05694577344af7d5430 100644 (file)
@@ -9,14 +9,15 @@
      \ /   This software is distributed as is, NO WARRANTY.              
       V_______________________________________________________________ *)
 
-module H = Hashtbl
 module U = NUri
+module H = U.UriHash
 module M = Meta
 module A = Aut
 
-type qid = M.id * M.id list (* qualified identifier: name, qualifiers *)
+(* qualified identifier: uri, name, qualifiers *)
+type qid = U.uri * M.id * M.id list
 
-type environment = (qid, M.pars) H.t
+type environment = M.pars H.t
 
 type context_node = qid option (* context node: None = root *)
 
@@ -27,7 +28,7 @@ type status = {
    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
@@ -37,20 +38,23 @@ let hsize = 7000 (* hash tables initial size *)
 
 (* Internal functions *******************************************************)
 
-let initial_status size = {
-   path = []; node = None; nodes = []; line = 1; explicit = true;
+let initial_status size cover = {
+   path = []; node = None; nodes = []; line = 1; cover = cover;
    henv = H.create size; hcnt = H.create size
 }
 
 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), 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 qs = f (mk_qid st id qs) in
    let f path = Cps.list_rev_append f path ~tail:qs in
    let rec skip f = function
       | phd :: ptl, qshd :: _ when phd = qshd -> f ptl
@@ -59,17 +63,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
       | []      -> assert false
    in
    Cps.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
@@ -87,26 +91,26 @@ 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 st.henv (uri_of_qid qid) in f qid (Some args)
    with Not_found -> f qid None
 
 let resolve_gref_relaxed f st qid =
    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 st.hcnt (uri_of_qid qid) in f pars None
       with Not_found -> f [] (Some node)
 
 let get_pars_relaxed f st =
    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
 
@@ -142,7 +146,7 @@ let rec xlate_term f st lenv = function
       resolve_lref f st l lenv (id_of_name name)
 
 let xlate_item f st = function
-   | A.Section (Some name)     ->
+   | A.Section (Some (_, name))     ->
       f {st with path = name :: st.path; nodes = st.node :: st.nodes} None
    | A.Section None            ->
       begin match st.path, st.nodes with
@@ -159,7 +163,7 @@ let xlate_item f st = function
       let f qid = 
          let f pars =
            let f ww = 
-              H.add st.hcnt qid ((name, ww) :: pars);
+              H.add st.hcnt (uri_of_qid qid) ((name, ww) :: pars);
               f {st with node = Some qid} None
            in
             xlate_term f st pars w
@@ -172,7 +176,7 @@ let xlate_item f st = function
          let f qid = 
             let f ww =
               let entry = (st.line, pars, uri_of_qid qid, ww, None) in
-              H.add st.henv qid pars;
+              H.add st.henv (uri_of_qid qid) pars;
               f {st with line = succ st.line} (Some entry)
            in
            xlate_term f st pars w
@@ -185,7 +189,7 @@ let xlate_item f st = function
          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;
+              H.add st.henv (uri_of_qid qid) pars;
               f {st with line = succ st.line} (Some entry)
            in
            let f ww = xlate_term (f ww) st pars v in
@@ -197,6 +201,7 @@ let xlate_item f st = function
 
 (* Interface functions ******************************************************)
 
-let initial_status = initial_status hsize
+let initial_status ?(cover="") () =
+   initial_status hsize cover
 
 let meta_of_aut = xlate_item