2016-02-18 07:11:59 -08:00
|
|
|
(**************************************************************************)
|
|
|
|
(* *)
|
|
|
|
(* OCaml *)
|
|
|
|
(* *)
|
|
|
|
(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *)
|
|
|
|
(* *)
|
|
|
|
(* Copyright 1996 Institut National de Recherche en Informatique et *)
|
|
|
|
(* en Automatique. *)
|
|
|
|
(* *)
|
|
|
|
(* All rights reserved. This file is distributed under the terms of *)
|
|
|
|
(* the GNU Lesser General Public License version 2.1, with the *)
|
|
|
|
(* special exception on linking described in the file LICENSE. *)
|
|
|
|
(* *)
|
|
|
|
(**************************************************************************)
|
1995-08-09 08:06:35 -07:00
|
|
|
|
2016-05-03 04:18:15 -07:00
|
|
|
(** Source code locations (ranges of positions), used in parsetree. *)
|
2002-11-01 09:06:47 -08:00
|
|
|
|
2000-03-06 14:12:09 -08:00
|
|
|
open Format
|
1995-05-04 03:15:53 -07:00
|
|
|
|
2002-11-01 09:06:47 -08:00
|
|
|
type t = {
|
|
|
|
loc_start: Lexing.position;
|
|
|
|
loc_end: Lexing.position;
|
|
|
|
loc_ghost: bool;
|
|
|
|
}
|
|
|
|
|
2016-05-03 04:18:15 -07:00
|
|
|
(** Note on the use of Lexing.position in this module.
|
2002-11-26 09:14:28 -08:00
|
|
|
If [pos_fname = ""], then use [!input_name] instead.
|
2002-12-12 02:48:49 -08:00
|
|
|
If [pos_lnum = -1], then [pos_bol = 0]. Use [pos_cnum] and
|
2002-11-26 09:14:28 -08:00
|
|
|
re-parse the file to get the line and character numbers.
|
|
|
|
Else all fields are correct.
|
|
|
|
*)
|
|
|
|
|
2002-11-01 09:06:47 -08:00
|
|
|
val none : t
|
|
|
|
(** An arbitrary value of type [t]; describes an empty ghost range. *)
|
2015-06-28 06:11:50 -07:00
|
|
|
|
|
|
|
val in_file : string -> t
|
2005-03-24 09:20:54 -08:00
|
|
|
(** Return an empty ghost range located in a given file. *)
|
2015-06-28 06:11:50 -07:00
|
|
|
|
2002-11-01 09:06:47 -08:00
|
|
|
val init : Lexing.lexbuf -> string -> unit
|
|
|
|
(** Set the file name and line number of the [lexbuf] to be the start
|
|
|
|
of the named file. *)
|
2015-06-28 06:11:50 -07:00
|
|
|
|
2002-11-01 09:06:47 -08:00
|
|
|
val curr : Lexing.lexbuf -> t
|
|
|
|
(** Get the location of the current token from the [lexbuf]. *)
|
1995-05-04 03:15:53 -07:00
|
|
|
|
1999-09-08 10:42:36 -07:00
|
|
|
val symbol_rloc: unit -> t
|
|
|
|
val symbol_gloc: unit -> t
|
2012-05-30 07:52:37 -07:00
|
|
|
|
|
|
|
(** [rhs_loc n] returns the location of the symbol at position [n], starting
|
|
|
|
at 1, in the current parser rule. *)
|
1995-05-04 03:15:53 -07:00
|
|
|
val rhs_loc: int -> t
|
|
|
|
|
|
|
|
val input_name: string ref
|
|
|
|
val input_lexbuf: Lexing.lexbuf option ref
|
|
|
|
|
2011-10-20 20:26:35 -07:00
|
|
|
val get_pos_info: Lexing.position -> string * int * int (* file, line, char *)
|
|
|
|
val print_loc: formatter -> t -> unit
|
2007-12-04 05:38:58 -08:00
|
|
|
val print_error: formatter -> t -> unit
|
2015-08-15 08:57:53 -07:00
|
|
|
val print_error_cur_file: formatter -> unit -> unit
|
2000-03-06 14:12:09 -08:00
|
|
|
val print_warning: t -> formatter -> Warnings.t -> unit
|
2015-07-17 07:31:05 -07:00
|
|
|
val formatter_for_warnings : formatter ref
|
2000-03-06 14:12:09 -08:00
|
|
|
val prerr_warning: t -> Warnings.t -> unit
|
1997-04-15 12:18:41 -07:00
|
|
|
val echo_eof: unit -> unit
|
1995-09-08 01:55:59 -07:00
|
|
|
val reset: unit -> unit
|
1997-11-12 04:32:53 -08:00
|
|
|
|
2015-04-26 14:05:26 -07:00
|
|
|
val warning_printer : (t -> formatter -> Warnings.t -> unit) ref
|
|
|
|
(** Hook for intercepting warnings. *)
|
2015-06-29 10:04:13 -07:00
|
|
|
|
2015-04-26 14:05:26 -07:00
|
|
|
val default_warning_printer : t -> formatter -> Warnings.t -> unit
|
|
|
|
(** Original warning printer for use in hooks. *)
|
|
|
|
|
2013-09-11 11:10:59 -07:00
|
|
|
val highlight_locations: formatter -> t list -> bool
|
2010-05-21 08:06:01 -07:00
|
|
|
|
2012-05-30 07:52:37 -07:00
|
|
|
type 'a loc = {
|
|
|
|
txt : 'a;
|
|
|
|
loc : t;
|
|
|
|
}
|
|
|
|
|
|
|
|
val mknoloc : 'a -> 'a loc
|
|
|
|
val mkloc : 'a -> t -> 'a loc
|
|
|
|
|
2010-05-21 08:06:01 -07:00
|
|
|
val print: formatter -> t -> unit
|
2016-01-13 08:20:23 -08:00
|
|
|
val print_compact: formatter -> t -> unit
|
2011-12-20 02:35:43 -08:00
|
|
|
val print_filename: formatter -> string -> unit
|
|
|
|
|
2014-04-06 08:06:22 -07:00
|
|
|
val absolute_path: string -> string
|
|
|
|
|
2012-03-07 09:27:59 -08:00
|
|
|
val show_filename: string -> string
|
|
|
|
(** In -absname mode, return the absolute path for this filename.
|
|
|
|
Otherwise, returns the filename unchanged. *)
|
2012-04-17 01:02:02 -07:00
|
|
|
|
2011-12-20 02:35:43 -08:00
|
|
|
|
|
|
|
val absname: bool ref
|
2013-09-11 09:08:00 -07:00
|
|
|
|
|
|
|
(* Support for located errors *)
|
|
|
|
|
|
|
|
type error =
|
|
|
|
{
|
|
|
|
loc: t;
|
|
|
|
msg: string;
|
|
|
|
sub: error list;
|
2013-09-11 11:10:59 -07:00
|
|
|
if_highlight: string; (* alternative message if locations are highlighted *)
|
2013-09-11 09:08:00 -07:00
|
|
|
}
|
|
|
|
|
2014-05-07 07:52:19 -07:00
|
|
|
exception Error of error
|
|
|
|
|
2015-08-15 08:57:53 -07:00
|
|
|
val print_error_prefix: formatter -> unit -> unit
|
|
|
|
(* print the prefix "Error:" possibly with style *)
|
|
|
|
|
2013-09-11 11:10:59 -07:00
|
|
|
val error: ?loc:t -> ?sub:error list -> ?if_highlight:string -> string -> error
|
|
|
|
|
2014-04-12 03:17:02 -07:00
|
|
|
val errorf: ?loc:t -> ?sub:error list -> ?if_highlight:string
|
2015-08-15 08:57:53 -07:00
|
|
|
-> ('a, Format.formatter, unit, error) format4 -> 'a
|
|
|
|
|
2014-08-07 02:46:34 -07:00
|
|
|
val raise_errorf: ?loc:t -> ?sub:error list -> ?if_highlight:string
|
2015-08-15 08:57:53 -07:00
|
|
|
-> ('a, Format.formatter, unit, 'b) format4 -> 'a
|
2014-08-07 02:46:34 -07:00
|
|
|
|
2013-09-11 09:08:00 -07:00
|
|
|
val error_of_printer: t -> (formatter -> 'a -> unit) -> 'a -> error
|
|
|
|
|
2013-09-12 06:47:04 -07:00
|
|
|
val error_of_printer_file: (formatter -> 'a -> unit) -> 'a -> error
|
|
|
|
|
2013-09-11 09:08:00 -07:00
|
|
|
val error_of_exn: exn -> error option
|
|
|
|
|
|
|
|
val register_error_of_exn: (exn -> error option) -> unit
|
|
|
|
(* Each compiler module which defines a custom type of exception
|
|
|
|
which can surface as a user-visible error should register
|
|
|
|
a "printer" for this exception using [register_error_of_exn].
|
|
|
|
The result of the printer is an [error] value containing
|
|
|
|
a location, a message, and optionally sub-messages (each of them
|
|
|
|
being located as well). *)
|
|
|
|
|
|
|
|
val report_error: formatter -> error -> unit
|
2013-09-12 07:45:03 -07:00
|
|
|
|
2015-04-26 14:05:26 -07:00
|
|
|
val error_reporter : (formatter -> error -> unit) ref
|
|
|
|
(** Hook for intercepting error reports. *)
|
2015-06-29 10:04:13 -07:00
|
|
|
|
2015-04-26 14:05:26 -07:00
|
|
|
val default_error_reporter : formatter -> error -> unit
|
|
|
|
(** Original error reporter for use in hooks. *)
|
|
|
|
|
2013-09-12 07:45:03 -07:00
|
|
|
val report_exception: formatter -> exn -> unit
|
|
|
|
(* Reraise the exception if it is unknown. *)
|