package override

  1. Overview
  2. Docs
include module type of struct include Location end with type t := Location.t and type report_printer := Location.report_printer and type report_kind := Location.report_kind and type report := Location.report and type msg := Location.msg and type 'a loc := 'a Location.loc and type error := Location.error

Source code locations (ranges of positions), used in parsetree

Warning: this module is unstable and part of compiler-libs.

Note on the use of Lexing.position in this module. If pos_fname = "", then use !input_name instead. If pos_lnum = -1, then pos_bol = 0. Use pos_cnum and re-parse the file to get the line and character numbers. Else all fields are correct.

val none : Location.t

An arbitrary value of type t; describes an empty ghost range.

val in_file : string -> Location.t

Return an empty ghost range located in a given file.

val init : Lexing.lexbuf -> string -> unit

Set the file name and line number of the lexbuf to be the start of the named file.

Get the location of the current token from the lexbuf.

val symbol_rloc : unit -> Location.t
val symbol_gloc : unit -> Location.t
val rhs_loc : int -> Location.t

rhs_loc n returns the location of the symbol at position n, starting at 1, in the current parser rule.

val rhs_interval : int -> int -> Location.t
val get_pos_info : Lexing.position -> string * int * int

file, line, char

val mknoloc : 'a -> 'a Location.loc
val mkloc : 'a -> Location.t -> 'a Location.loc

Input info

val input_name : string ref
val input_lexbuf : Lexing.lexbuf option ref

Toplevel-specific functions

val echo_eof : unit -> unit
val reset : unit -> unit

Printing locations

val rewrite_absolute_path : string -> string

rewrite absolute path to honor the BUILD_PATH_PREFIX_MAP variable (https://reproducible-builds.org/specs/build-path-prefix-map/) if it is set.

val absolute_path : string -> string
val show_filename : string -> string

In -absname mode, return the absolute path for this filename. Otherwise, returns the filename unchanged.

val print_filename : Format.formatter -> string -> unit
val print_loc : Format.formatter -> Location.t -> unit
val print_locs : Format.formatter -> Location.t list -> unit

Toplevel-specific location highlighting

val highlight_terminfo : Lexing.lexbuf -> Format.formatter -> Location.t list -> unit

Reporting errors and warnings

The type of reports and report printers

val msg : ?loc:Location.t -> ('a, Format.formatter, unit, Location.msg) format4 -> 'a

Report printers used in the compiler

val batch_mode_printer : Location.report_printer
val terminfo_toplevel_printer : Lexing.lexbuf -> Location.report_printer
val best_toplevel_printer : unit -> Location.report_printer

Detects the terminal capabilities and selects an adequate printer

Printing a report

val print_report : Format.formatter -> Location.report -> unit

Display an error or warning report.

val report_printer : (unit -> Location.report_printer) ref

Hook for redefining the printer of reports.

The hook is a unit -> report_printer and not simply a report_printer: this is useful so that it can detect the type of the output (a file, a terminal, ...) and select a printer accordingly.

val default_report_printer : unit -> Location.report_printer

Original report printer for use in hooks.

Reporting warnings

Converting a Warnings.t into a report

val report_warning : Location.t -> Warnings.t -> Location.report option

report_warning loc w produces a report for the given warning w, or None if the warning is not to be printed.

val warning_reporter : (Location.t -> Warnings.t -> Location.report option) ref

Hook for intercepting warnings.

val default_warning_reporter : Location.t -> Warnings.t -> Location.report option

Original warning reporter for use in hooks.

Printing warnings

val formatter_for_warnings : Format.formatter ref
val print_warning : Location.t -> Format.formatter -> Warnings.t -> unit

Prints a warning. This is simply the composition of report_warning and print_report.

val prerr_warning : Location.t -> Warnings.t -> unit

Same as print_warning, but uses !formatter_for_warnings as output formatter.

Reporting alerts

Converting an Alert.t into a report

val report_alert : Location.t -> Warnings.alert -> Location.report option

report_alert loc w produces a report for the given alert w, or None if the alert is not to be printed.

val alert_reporter : (Location.t -> Warnings.alert -> Location.report option) ref

Hook for intercepting alerts.

val default_alert_reporter : Location.t -> Warnings.alert -> Location.report option

Original alert reporter for use in hooks.

Printing alerts

val print_alert : Location.t -> Format.formatter -> Warnings.alert -> unit

Prints an alert. This is simply the composition of report_alert and print_report.

val prerr_alert : Location.t -> Warnings.alert -> unit

Same as print_alert, but uses !formatter_for_warnings as output formatter.

val deprecated : ?def:Location.t -> ?use:Location.t -> Location.t -> string -> unit

Prints a deprecation alert.

val alert : ?def:Location.t -> ?use:Location.t -> kind:string -> Location.t -> string -> unit

Prints an arbitrary alert.

Reporting errors

val error : ?loc:Location.t -> ?sub:Location.msg list -> string -> Location.error
val errorf : ?loc:Location.t -> ?sub:Location.msg list -> ('a, Format.formatter, unit, Location.error) format4 -> 'a
val error_of_printer : ?loc:Location.t -> ?sub:Location.msg list -> (Format.formatter -> 'a -> unit) -> 'a -> Location.error
val error_of_printer_file : (Format.formatter -> 'a -> unit) -> 'a -> Location.error

Automatically reporting errors for raised exceptions

val register_error_of_exn : (exn -> Location.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 error_of_exn : exn -> [ `Ok of Location.error | `Already_displayed ] option
exception Error of Location.error

Raising Error e signals an error e; the exception will be caught and the error will be printed.

exception Already_displayed_error

Raising Already_displayed_error signals an error which has already been printed. The exception will be caught, but nothing will be printed

val raise_errorf : ?loc:Location.t -> ?sub:Location.msg list -> ('a, Format.formatter, unit, 'b) format4 -> 'a
val report_exception : Format.formatter -> exn -> unit

Reraise the exception if it is unknown.

type t = Warnings.loc = {
  1. loc_start : Stdlib.Lexing.position;
  2. loc_end : Stdlib.Lexing.position;
  3. loc_ghost : bool;
}
val show : t -> string
type 'a loc = 'a Location.loc = {
  1. txt : 'a;
  2. loc : t;
}
val pp_loc : (Ppx_show_runtime.Format.formatter -> 'a -> unit) -> Ppx_show_runtime.Format.formatter -> 'a loc -> unit
val show_loc : (Ppx_show_runtime.Format.formatter -> 'a -> unit) -> 'a loc -> string
type msg = (Stdlib.Format.formatter -> unit) loc
val pp_msg : Ppx_show_runtime.Format.formatter -> msg -> unit
val show_msg : msg -> string
type report_kind = Location.report_kind =
  1. | Report_error
  2. | Report_warning of string
  3. | Report_warning_as_error of string
  4. | Report_alert of string
  5. | Report_alert_as_error of string
val pp_report_kind : Ppx_show_runtime.Format.formatter -> report_kind -> unit
val show_report_kind : report_kind -> string
type report = Location.report = {
  1. kind : report_kind;
  2. main : msg;
  3. sub : msg list;
}
val pp_report : Ppx_show_runtime.Format.formatter -> report -> unit
val show_report : report -> string
type report_printer = Location.report_printer = {
  1. pp : report_printer -> Stdlib.Format.formatter -> report -> unit;
  2. pp_report_kind : report_printer -> report -> Stdlib.Format.formatter -> report_kind -> unit;
  3. pp_main_loc : report_printer -> report -> Stdlib.Format.formatter -> t -> unit;
  4. pp_main_txt : report_printer -> report -> Stdlib.Format.formatter -> (Stdlib.Format.formatter -> unit) -> unit;
  5. pp_submsgs : report_printer -> report -> Stdlib.Format.formatter -> msg list -> unit;
  6. pp_submsg : report_printer -> report -> Stdlib.Format.formatter -> msg -> unit;
  7. pp_submsg_loc : report_printer -> report -> Stdlib.Format.formatter -> t -> unit;
  8. pp_submsg_txt : report_printer -> report -> Stdlib.Format.formatter -> (Stdlib.Format.formatter -> unit) -> unit;
}
val pp_report_printer : Ppx_show_runtime.Format.formatter -> report_printer -> unit
val show_report_printer : report_printer -> string
type error = report
val pp_error : Ppx_show_runtime.Format.formatter -> error -> unit
val show_error : error -> string
OCaml

Innovation. Community. Security.