error.mli 3.55 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13
(******************************************************************************)
(*                                                                            *)
(*                                   Menhir                                   *)
(*                                                                            *)
(*                       François Pottier, Inria Paris                        *)
(*              Yann Régis-Gianas, PPS, Université Paris Diderot              *)
(*                                                                            *)
(*  Copyright Inria. All rights reserved. This file is distributed under the  *)
(*  terms of the GNU General Public License version 2, as described in the    *)
(*  file LICENSE.                                                             *)
(*                                                                            *)
(******************************************************************************)

14
(* This module helps report errors. *)
15 16 17

(* ---------------------------------------------------------------------------- *)

18 19 20 21 22 23 24
(* A mechanism to turn all display (logging, warnings, errors) on and off. *)

val enable: unit -> unit
val disable: unit -> unit

(* ---------------------------------------------------------------------------- *)

25 26 27 28 29 30 31 32 33 34
(* Logging and log levels. *)

val logG: int -> (out_channel -> unit) -> unit
val logA: int -> (out_channel -> unit) -> unit
val logC: int -> (out_channel -> unit) -> unit

(* ---------------------------------------------------------------------------- *)

(* Errors and warnings. *)

35 36 37
(* [error ps format ...] displays the list of positions [ps], followed with the
   error message [format ...], and exits. The strings "Error: " and "\n" are
   automatically added at the beginning and end of the error message. The
38
   message should begin with a lowercase letter and end with a dot. *)
39

40
val error: Positions.positions -> ('a, out_channel, unit, 'b) format4 -> 'a
41

42
(* [errorp] is like [error], but uses the position range carried by [v]. *)
43

44
val errorp: _ Positions.located -> ('a, out_channel, unit, 'b) format4 -> 'a
45

46
(* [warning] is like [error], except it does not exit. *)
47

48 49 50
val warning: Positions.positions -> ('a, out_channel, unit, unit) format4 -> 'a

(* ---------------------------------------------------------------------------- *)
51

52
(* Delayed error reports -- where multiple errors can be reported at once. *)
53

54
(* A category of errors. *)
55

56
type category
57

58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
(* [new_category()] creates a new category of errors. *)

val new_category: unit -> category

(* [signal category] is like [error], except it does not exit immediately. It
   records the fact that an error of this category has occurred. This can be
   later detected by [exit_if category]. *)

val signal: category -> Positions.positions -> ('a, out_channel, unit, unit) format4 -> 'a

(* [exit_if category] exits with exit code 1 if [signal category] was
   previously called. Together, [signal] and [exit_if] allow reporting
   multiple errors before aborting. *)

val exit_if: category -> unit

(* ---------------------------------------------------------------------------- *)

(* Certain warnings about the grammar can optionally be treated as errors. *)

val grammatical_error: category
79

80 81 82 83
(* [grammar_warning] emits a warning or error message, via either [warning] or
   [signal grammatical_error]. It does not stop the program; the client must
   at some point use [exit_if grammatical_error] and stop the program if any
   errors have been reported. *)
84

85
val grammar_warning: Positions.positions -> ('a, out_channel, unit, unit) format4 -> 'a