1995-08-09 08:06:35 -07:00
|
|
|
(***********************************************************************)
|
|
|
|
(* *)
|
2011-07-27 07:17:02 -07:00
|
|
|
(* OCaml *)
|
1995-08-09 08:06:35 -07:00
|
|
|
(* *)
|
|
|
|
(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *)
|
|
|
|
(* *)
|
1996-04-30 07:53:58 -07:00
|
|
|
(* Copyright 1996 Institut National de Recherche en Informatique et *)
|
1999-11-17 10:59:06 -08:00
|
|
|
(* en Automatique. All rights reserved. This file is distributed *)
|
|
|
|
(* under the terms of the Q Public License version 1.0. *)
|
1995-08-09 08:06:35 -07:00
|
|
|
(* *)
|
|
|
|
(***********************************************************************)
|
|
|
|
|
2002-11-01 09:06:47 -08:00
|
|
|
(* Source code locations (ranges of positions), used in parsetree. *)
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2002-11-26 09:14:28 -08:00
|
|
|
(* Note on the use of Lexing.position in this module.
|
|
|
|
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. *)
|
2005-03-24 09:20:54 -08:00
|
|
|
val in_file : string -> t;;
|
|
|
|
(** Return an empty ghost range located in a given file. *)
|
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. *)
|
|
|
|
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
|
|
|
|
val print_error_cur_file: formatter -> unit
|
2000-03-06 14:12:09 -08:00
|
|
|
val print_warning: t -> formatter -> Warnings.t -> unit
|
|
|
|
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
|
|
|
|
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
|
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
|
|
|
|
|
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
|
|
|
|
-> ('a, unit, string, error) format4 -> 'a
|
2013-09-11 09:08:00 -07:00
|
|
|
|
2014-08-07 02:46:34 -07:00
|
|
|
val raise_errorf: ?loc:t -> ?sub:error list -> ?if_highlight:string
|
|
|
|
-> ('a, unit, string, 'b) format4 -> 'a
|
|
|
|
|
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
|
|
|
|
|
|
|
val report_exception: formatter -> exn -> unit
|
|
|
|
(* Reraise the exception if it is unknown. *)
|