]> matita.cs.unibo.it Git - helm.git/blobdiff - matita/matita/matitaEngine.ml
Bug "fixed" (i.e avoided).
[helm.git] / matita / matita / matitaEngine.ml
index 64b3cc1ebbc0d8a19407bcceb5fbce7f6034c60f..f65c8432a4000f3dc9f28031eb0d5a03bc2c4174 100644 (file)
@@ -29,8 +29,14 @@ module G = GrafiteAst
 open GrafiteTypes
 open Printf
 
+class status baseuri =
+ object
+  inherit GrafiteTypes.status baseuri
+  inherit ApplyTransformation.status
+ end
+
 exception TryingToAdd of string Lazy.t
-exception EnrichedWithStatus of exn * GrafiteTypes.status
+exception EnrichedWithStatus of exn * status
 exception AlreadyLoaded of string Lazy.t
 exception FailureCompiling of string * exn
 exception CircularDependency of string
@@ -40,8 +46,8 @@ let debug_print = if debug then prerr_endline else ignore ;;
 
 let slash_n_RE = Pcre.regexp "\\n" ;;
 
-let pp_ast_statement grafite_status stm =
-  let stm = GrafiteAstPp.pp_statement stm
+let pp_ast_statement status stm =
+  let stm = GrafiteAstPp.pp_statement status stm
     ~map_unicode_to_tex:(Helm_registry.get_bool "matita.paste_unicode_as_tex")
   in
   let stm = Pcre.replace ~rex:slash_n_RE stm in
@@ -168,14 +174,14 @@ let rec get_ast status ~compiling ~asserted ~include_paths strm =
 
 and eval_from_stream ~compiling ~asserted ~include_paths ?do_heavy_checks status str cb =
  let matita_debug = Helm_registry.get_bool "matita.debug" in
- let rec loop asserted status =
-  let asserted,stop,status = 
+ let rec loop asserted status str =
+  let asserted,stop,status,str = 
    try
      let cont =
        try Some (get_ast status ~compiling ~asserted ~include_paths str)
        with End_of_file -> None in
      match cont with
-     | None -> asserted, true, status
+     | None -> asserted, true, status, str
      | Some (asserted,ast) ->
         cb status ast;
         let new_statuses =
@@ -185,15 +191,25 @@ and eval_from_stream ~compiling ~asserted ~include_paths ?do_heavy_checks status
             [s,None] -> s
           | _::(_,Some (_,value))::_ ->
                 raise (TryingToAdd (lazy (GrafiteAstPp.pp_alias value)))
-          | _ -> assert false
+          | _ -> assert false in
+        (* CSC: complex patch to re-build the lexer since the tokens may
+           have changed. Note: this way we loose look-ahead tokens.
+           Hence the "include" command must be terminated (no look-ahead) *)
+        let str =
+         match ast with
+            (GrafiteAst.Executable
+              (_,GrafiteAst.NCommand (_,GrafiteAst.Include (_,_,_)))) ->
+              GrafiteParser.parsable_statement status
+               (GrafiteParser.strm_of_parsable str)
+          | _ -> str
         in
-         asserted, false, status
+         asserted, false, status, str
    with exn when not matita_debug ->
      raise (EnrichedWithStatus (exn, status))
   in
-  if stop then asserted,status else loop asserted status
+  if stop then asserted,status else loop asserted status str
  in
-  loop asserted status
+  loop asserted status str
 
 and compile ~compiling ~asserted ~include_paths fname =
   if List.mem fname compiling then raise (CircularDependency fname);
@@ -204,7 +220,7 @@ and compile ~compiling ~asserted ~include_paths fname =
   if Http_getter_storage.is_read_only baseuri then assert false;
   activate_extraction baseuri fname ;
   (* MATITA 1.0: debbo fare time_travel sulla ng_library? *)
-  let grafite_status = new GrafiteTypes.status baseuri in
+  let status = new status baseuri in
   let big_bang = Unix.gettimeofday () in
   let { Unix.tms_utime = big_bang_u ; Unix.tms_stime = big_bang_s} = 
     Unix.times () 
@@ -238,19 +254,19 @@ and compile ~compiling ~asserted ~include_paths fname =
           (Http_getter.filename ~local:true ~writable:true (baseuri ^
           "foo.con")));
     let buf =
-     GrafiteParser.parsable_statement grafite_status
+     GrafiteParser.parsable_statement status
       (Ulexing.from_utf8_channel (open_in fname))
     in
     let print_cb =
       if not (Helm_registry.get_bool "matita.verbose") then (fun _ _ -> ())
       else pp_ast_statement
     in
-    let asserted, grafite_status =
-     eval_from_stream ~compiling ~asserted ~include_paths grafite_status buf print_cb in
+    let asserted, status =
+     eval_from_stream ~compiling ~asserted ~include_paths status buf print_cb in
     let elapsed = Unix.time () -. time in
      (if Helm_registry.get_bool "matita.moo" then begin
        GrafiteTypes.Serializer.serialize ~baseuri:(NUri.uri_of_string baseuri)
-        grafite_status
+        status
      end;
      let tm = Unix.gmtime elapsed in
      let sec = string_of_int tm.Unix.tm_sec ^ "''" in