]> matita.cs.unibo.it Git - helm.git/blob - helm/matita/matitaExcPp.ml
More compact disambiguation errors.
[helm.git] / helm / 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 open Printf
27
28 let rec to_string = 
29   function
30   | HExtlib.Localized (floc,exn) ->
31       let _,msg = to_string exn in
32       let (x, y) = HExtlib.loc_of_floc floc in
33        Some floc, sprintf "Error at %d-%d: %s" x y msg
34   | GrafiteTypes.Option_error ("baseuri", "not found" ) -> 
35       None,
36       "Baseuri not set for this script. "
37       ^ "Use 'set \"baseuri\" \"<uri>\".' to set it."
38   | GrafiteTypes.Command_error msg -> None, "Error: " ^ msg
39   | CicNotationParser.Parse_error err ->
40       None, sprintf "Parse error: %s" err
41   | UriManager.IllFormedUri uri -> None, sprintf "invalid uri: %s" uri
42   | CicEnvironment.Object_not_found uri ->
43       None, sprintf "object not found: %s" (UriManager.string_of_uri uri)
44   | Unix.Unix_error (code, api, param) ->
45       let err = Unix.error_message code in
46       None, "Unix Error (" ^ api ^ "): " ^ err
47   | GrafiteMarshal.Corrupt_moo fname ->
48       None, sprintf ".moo file '%s' is corrupt (shorter than expected)" fname
49   | GrafiteMarshal.Checksum_failure fname ->
50       None,
51        sprintf "checksum failed for .moo file '%s', please recompile it'" fname
52   | GrafiteMarshal.Version_mismatch fname ->
53       None,
54       sprintf
55         (".moo file '%s' has been compiled by a different version of matita, "
56         ^^ "please recompile it")
57         fname
58   | ProofEngineTypes.Fail msg -> None, "Tactic error: " ^ Lazy.force msg
59   | Continuationals.Error s -> None, "Tactical error: " ^ Lazy.force s
60   | CicTypeChecker.TypeCheckerFailure msg ->
61      None, "Type checking error: " ^ Lazy.force msg
62   | CicTypeChecker.AssertFailure msg ->
63      None, "Type checking assertion failed: " ^ Lazy.force msg
64   | LibrarySync.AlreadyDefined s -> 
65      None, "Already defined: " ^ UriManager.string_of_uri s
66   | MatitaDisambiguator.DisambiguationError (offset,errorll) ->
67      let rec aux n ?(dummy=false) (prev_msg,phases) =
68       function
69          [] -> []
70        | phase::tl ->
71           let msg =
72            String.concat "\n\n\n"
73             (List.map (fun (floc,msg) ->
74               let loc_descr =
75                match floc with
76                   None -> ""
77                 | Some floc ->
78                    let (x, y) = HExtlib.loc_of_floc floc in
79                     sprintf " at %d-%d" (x+offset) (y+offset)
80               in
81                "*Error" ^ loc_descr ^ ": " ^ Lazy.force msg) phase)
82           in
83            if msg = prev_msg then
84             aux (n+1) (msg,phases@[n]) tl
85            else
86             (if not dummy then [prev_msg,phases] else []) @
87              (aux (n+1) (msg,[n]) tl) in
88      let loc =
89       match errorll with
90          ((Some floc,_)::_)::_ ->
91           let (x, y) = HExtlib.loc_of_floc floc in
92           let x = x + offset in
93           let y = y + offset in
94           let flocb,floce = floc in
95           let floc =
96            {flocb with Lexing.pos_cnum = x}, {floce with Lexing.pos_cnum = y}
97           in
98            Some floc
99        | _ -> None in
100      let rec explain =
101       function
102          [] -> ""
103        | (msg,phases)::tl ->
104            explain tl ^
105            "***** Errors obtained during phase" ^
106             (if phases = [] then " " else "s ") ^
107             String.concat "," (List.map string_of_int phases) ^": *****\n"^
108             msg ^ "\n\n"
109      in
110       loc,
111        "********** DISAMBIGUATION ERRORS: **********\n" ^
112         explain (aux 1 ~dummy:true ("",[]) errorll)
113   | exn -> None, "Uncaught exception: " ^ Printexc.to_string exn
114