]> matita.cs.unibo.it Git - helm.git/blob - matita/matitaExcPp.ml
c3c78929ff8e978eae839c1cf7cf677940df4778
[helm.git] / matita / matitaExcPp.ml
1 (* Copyright (C) 2004-2005, HELM Team.
2  * 
3  * This file is part of HELM, an Hypertextual, Electronic
4  * Library of Mathematics, developed at the Computer Science
5  * Department, University of Bologna, Italy.
6  * 
7  * HELM is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  * 
12  * HELM is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with HELM; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
20  * MA  02111-1307, USA.
21  * 
22  * For details, see the HELM World-Wide-Web page,
23  * http://helm.cs.unibo.it/
24  *)
25
26 (* $Id$ *)
27
28 open Printf
29
30 let rec to_string = 
31   function
32   | HExtlib.Localized (floc,exn) ->
33       let _,msg = to_string exn in
34       let (x, y) = HExtlib.loc_of_floc floc in
35        Some floc, sprintf "Error at %d-%d: %s" x y msg
36   | GrafiteTypes.Option_error ("baseuri", "not found" ) -> 
37       None,
38       "Baseuri not set for this script. "
39       ^ "Use 'set \"baseuri\" \"<uri>\".' to set it."
40   | GrafiteTypes.Command_error msg -> None, "Error: " ^ msg
41   | CicNotationParser.Parse_error err ->
42       None, sprintf "Parse error: %s" err
43   | UriManager.IllFormedUri uri -> None, sprintf "invalid uri: %s" uri
44   | CicEnvironment.Object_not_found uri ->
45       None, sprintf "object not found: %s" (UriManager.string_of_uri uri)
46   | Unix.Unix_error (code, api, param) ->
47       let err = Unix.error_message code in
48       None, "Unix Error (" ^ api ^ "): " ^ err
49   | HMarshal.Corrupt_file fname -> None, sprintf "file '%s' is corrupt" fname
50   | HMarshal.Format_mismatch fname
51   | HMarshal.Version_mismatch fname ->
52       None,
53       sprintf "format/version mismatch for file '%s', please recompile it'"
54         fname
55   | ProofEngineTypes.Fail msg -> None, "Tactic error: " ^ Lazy.force msg
56   | Continuationals.Error s -> None, "Tactical error: " ^ Lazy.force s
57   | ProofEngineHelpers.Bad_pattern msg ->
58      None, "Bad pattern: " ^ Lazy.force msg
59   | CicRefine.RefineFailure msg ->
60      None, "Refiner error: " ^ Lazy.force msg
61   | CicTypeChecker.TypeCheckerFailure msg ->
62      None, "Type checking error: " ^ Lazy.force msg
63   | CicTypeChecker.AssertFailure msg ->
64      None, "Type checking assertion failed: " ^ Lazy.force msg
65   | LibrarySync.AlreadyDefined s -> 
66      None, "Already defined: " ^ UriManager.string_of_uri s
67   | CoercDb.EqCarrNotImplemented msg ->
68      None, ("EqCarrNotImplemented: " ^ Lazy.force msg)
69   | GrafiteDisambiguator.DisambiguationError (offset,errorll) ->
70      let rec aux n ?(dummy=false) (prev_msg,phases) =
71       function
72          [] -> [prev_msg,phases]
73        | phase::tl ->
74           let msg =
75            String.concat "\n\n\n"
76             (List.map (fun (_,_,floc,msg,significant) ->
77               let loc_descr =
78                match floc with
79                   None -> ""
80                 | Some floc ->
81                    let (x, y) = HExtlib.loc_of_floc floc in
82                     sprintf " at %d-%d" (x+offset) (y+offset)
83               in
84                "*" ^ (if not significant then "(Ignorable) " else "")
85                ^ "Error" ^ loc_descr ^ ": " ^ Lazy.force msg) phase)
86           in
87            if msg = prev_msg then
88             aux (n+1) (msg,phases@[n]) tl
89            else
90             (if not dummy then [prev_msg,phases] else []) @
91              (aux (n+1) (msg,[n]) tl) in
92      let loc =
93       match errorll with
94          ((_,_,Some floc,_,_)::_)::_ ->
95           let (x, y) = HExtlib.loc_of_floc floc in
96           let x = x + offset in
97           let y = y + offset in
98           let flocb,floce = floc in
99           let floc =
100            {flocb with Lexing.pos_cnum = x}, {floce with Lexing.pos_cnum = y}
101           in
102            Some floc
103        | _ -> None in
104      let rec explain =
105       function
106          [] -> ""
107        | (msg,phases)::tl ->
108            explain tl ^
109            "***** Errors obtained during phase" ^
110             (if phases = [] then " " else "s ") ^
111             String.concat "," (List.map string_of_int phases) ^": *****\n"^
112             msg ^ "\n\n"
113      in
114       loc,
115        "********** DISAMBIGUATION ERRORS: **********\n" ^
116         explain (aux 1 ~dummy:true ("",[]) errorll)
117   | exn -> None, "Uncaught exception: " ^ Printexc.to_string exn
118