]> matita.cs.unibo.it Git - helm.git/blobdiff - components/binaries/transcript/engine.ml
Big progress
[helm.git] / components / binaries / transcript / engine.ml
index 3b1e8d773294c963dabd001356b29e593dda661d..66c6c33be85a2b53e16352a7c41b57e77ee2a8d0 100644 (file)
@@ -143,6 +143,12 @@ let require st name inc =
 let get_coercion st str =
    try List.assoc str st.coercions with Not_found -> ""
 
+let make_path path =
+   List.fold_left Filename.concat "" (List.rev path)
+
+let make_prefix path =
+   String.concat "__" (List.rev path) ^ "__"
+
 let commit st name =
    let i = get_index st name in
    let script = st.scripts.(i) in
@@ -165,24 +171,29 @@ let produce st =
    let produce st name =
       let in_base_uri = Filename.concat st.input_base_uri name in
       let out_base_uri = Filename.concat st.output_base_uri name in
-      let filter = function
-         | T.Inline (k, obj)   -> 
+      let filter path = function
+         | T.Inline (b, k, obj, p)      -> 
+           let obj, p = 
+              if b then Filename.concat (make_path path) obj, make_prefix path
+              else obj, p
+           in 
            let s = obj ^ G.string_of_inline_kind k in
-           Some (T.Inline (k, Filename.concat in_base_uri s))
-        | T.Include s         ->
+           path, Some (T.Inline (b, k, Filename.concat in_base_uri s, p))
+        | T.Include s                  ->
            begin 
-              try Some (T.Include (List.assoc s st.requires))
-              with Not_found -> None
+              try path, Some (T.Include (List.assoc s st.requires))
+              with Not_found -> path, None
            end
-        | T.Coercion (b, obj) ->
+        | T.Coercion (b, obj)          ->
            let str = get_coercion st obj in
-           let base_uri = 
-              if str <> "" then str else 
-              if b then out_base_uri else in_base_uri
-           in
+           if str <> "" then path, Some (T.Coercion (b, str)) else
+           let base_uri = if b then out_base_uri else in_base_uri in
            let s = obj ^ G.string_of_inline_kind T.Con in
-           Some (T.Coercion (b, Filename.concat base_uri s))
-        | item                -> Some item
+           path, Some (T.Coercion (b, Filename.concat base_uri s))
+        | T.Section (b, id, _) as item ->
+           let path = if b then id :: path else List.tl path in
+           path, Some item
+        | item                         -> path, Some item
       in
       Printf.eprintf "processing file name: %s ...\n" name; flush stderr; 
       let file = Filename.concat st.input_path (name ^ st.script_ext) in
@@ -190,8 +201,9 @@ let produce st =
       let lexbuf = Lexing.from_channel ich in
       try 
          let items = V8Parser.items V8Lexer.token lexbuf in
-         close_in ich;
-         let items = List.rev (X.list_rev_map_filter filter items) in
+         close_in ich; 
+        let _, rev_items = X.list_rev_map_filter_fold filter [] items in
+        let items = List.rev rev_items in
         let local_items, global_items = List.partition partition items in
         let comment = T.Line (Printf.sprintf "From %s" name) in 
         if global_items <> [] then 
@@ -201,6 +213,6 @@ let produce st =
       with e -> 
          prerr_endline (Printexc.to_string e); close_in ich 
    in
-   init st.input_package; 
+   init st.input_package; require st st.input_package "preamble"; 
    List.iter (produce st) st.files; 
    commit st st.input_package