]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/matita/matitaExcPp.ml
New implementation for localized exceptions.
[helm.git] / helm / matita / matitaExcPp.ml
index 3ad6da153095dac5c56a026a084e1aabb147342c..2d0f60c9e6e4ec7fc749a99aee76e661918606d7 100644 (file)
 
 open Printf
 
-let to_string = 
+let rec to_string = 
   function
+  | HExtlib.Localized (floc,exn) ->
+      let _,msg = to_string exn in
+      let (x, y) = HExtlib.loc_of_floc floc in
+       Some floc, sprintf "Error at %d-%d: %s" x y msg
   | MatitaTypes.Option_error ("baseuri", "not found" ) -> 
+      None,
       "Baseuri not set for this script. "
       ^ "Use 'set \"baseuri\" \"<uri>\".' to set it."
-  | MatitaTypes.Command_error msg -> "Error: " ^ msg
-  | CicNotationParser.Parse_error (floc,err) ->
-      let (x, y) = CicNotationPt.loc_of_floc floc in
-      sprintf "Parse error at %d-%d: %s" x y err
-  | UriManager.IllFormedUri uri -> sprintf "invalid uri: %s" uri
+  | MatitaTypes.Command_error msg -> None, "Error: " ^ msg
+  | CicNotationParser.Parse_error err ->
+      None, sprintf "Parse error: %s" err
+  | UriManager.IllFormedUri uri -> None, sprintf "invalid uri: %s" uri
   | CicEnvironment.Object_not_found uri ->
-      sprintf "object not found: %s" (UriManager.string_of_uri uri)
+      None, sprintf "object not found: %s" (UriManager.string_of_uri uri)
   | Unix.Unix_error (code, api, param) ->
       let err = Unix.error_message code in
-      "Unix Error (" ^ api ^ "): " ^ err
+      None, "Unix Error (" ^ api ^ "): " ^ err
   | MatitaMoo.Corrupt_moo fname ->
-      sprintf ".moo file '%s' is corrupt (shorter than expected)" fname
+      None, sprintf ".moo file '%s' is corrupt (shorter than expected)" fname
   | MatitaMoo.Checksum_failure fname ->
-      sprintf "checksum failed for .moo file '%s', please recompile it'" fname
+      None,
+       sprintf "checksum failed for .moo file '%s', please recompile it'" fname
   | MatitaMoo.Version_mismatch fname ->
+      None,
       sprintf
         (".moo file '%s' has been compiled by a different version of matita, "
         ^^ "please recompile it")
         fname
-  | ProofEngineTypes.Fail msg -> "Tactic error: " ^ Lazy.force msg
-  | Continuationals.Error s -> "Tactical error: " ^ Lazy.force s
+  | ProofEngineTypes.Fail msg -> None, "Tactic error: " ^ Lazy.force msg
+  | Continuationals.Error s -> None, "Tactical error: " ^ Lazy.force s
   | CicTypeChecker.TypeCheckerFailure msg ->
-     "Type checking error: " ^ Lazy.force msg
+     None, "Type checking error: " ^ Lazy.force msg
   | CicTypeChecker.AssertFailure msg ->
-     "Type checking assertion failed: " ^ Lazy.force msg
+     None, "Type checking assertion failed: " ^ Lazy.force msg
   | MatitaDisambiguator.DisambiguationError errorll ->
      let rec aux n =
       function
@@ -66,7 +72,8 @@ let to_string =
              (List.map (fun msg -> "*Error: " ^ Lazy.force msg) phase) ^
             "\n\n\n"
      in
-      "********** DISAMBIGUATION ERRORS: **********\n" ^
-       aux 1 errorll
-  | exn -> "Uncaught exception: " ^ Printexc.to_string exn
+      None,
+       "********** DISAMBIGUATION ERRORS: **********\n" ^
+        aux 1 errorll
+  | exn -> None, "Uncaught exception: " ^ Printexc.to_string exn