Add copyright notices and new function String.chomp
[ocaml.git] / parsing / syntaxerr.ml
blob182863f132386deac6be6c797ff8de0d41046dae
1 (***********************************************************************)
2 (* *)
3 (* Objective Caml *)
4 (* *)
5 (* Xavier Leroy, projet Cristal, INRIA Rocquencourt *)
6 (* *)
7 (* Copyright 1997 Institut National de Recherche en Informatique et *)
8 (* en Automatique. All rights reserved. This file is distributed *)
9 (* under the terms of the Q Public License version 1.0. *)
10 (* *)
11 (***********************************************************************)
13 (* $Id$ *)
15 (* Auxiliary type for reporting syntax errors *)
17 open Format
19 type error =
20 Unclosed of Location.t * string * Location.t * string
21 | Other of Location.t
23 exception Error of error
24 exception Escape_error
26 let report_error ppf = function
27 | Unclosed(opening_loc, opening, closing_loc, closing) ->
28 if String.length !Location.input_name = 0
29 && Location.highlight_locations ppf opening_loc closing_loc
30 then fprintf ppf "Syntax error: '%s' expected, \
31 the highlighted '%s' might be unmatched" closing opening
32 else begin
33 fprintf ppf "%aSyntax error: '%s' expected@."
34 Location.print closing_loc closing;
35 fprintf ppf "%aThis '%s' might be unmatched"
36 Location.print opening_loc opening
37 end
38 | Other loc ->
39 fprintf ppf "%aSyntax error" Location.print loc