package ppxx

  1. Overview
  2. Docs
include module type of struct include Migrate_parsetree.Ast_405.Location end
type t = Warnings.loc = {
  1. loc_start : Lexing.position;
  2. loc_end : Lexing.position;
  3. loc_ghost : bool;
}

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 : t

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

val in_file : string -> 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.

val curr : Lexing.lexbuf -> t

Get the location of the current token from the lexbuf.

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

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

val input_name : string ref
val input_lexbuf : Lexing.lexbuf option ref
val get_pos_info : Lexing.position -> string * int * int
val print_loc : Format.formatter -> t -> unit
val print_error_prefix : Format.formatter -> unit
val print_error : Format.formatter -> t -> unit
val print_error_cur_file : Format.formatter -> unit -> unit
val print_warning : t -> Format.formatter -> Warnings.t -> unit
val formatter_for_warnings : Format.formatter ref
val prerr_warning : t -> Warnings.t -> unit
val echo_eof : unit -> unit
val reset : unit -> unit
val default_printer : Format.formatter -> t -> unit
val printer : (Format.formatter -> t -> unit) ref
val warning_printer : (t -> Format.formatter -> Warnings.t -> unit) ref

Hook for intercepting warnings.

val default_warning_printer : t -> Format.formatter -> Warnings.t -> unit

Original warning printer for use in hooks.

val highlight_locations : Format.formatter -> t list -> bool
val show_code_at_location : Format.formatter -> Lexing.lexbuf -> t -> unit
type 'a loc = 'a Location.loc = {
  1. txt : 'a;
  2. loc : t;
}
val mknoloc : 'a -> 'a loc
val mkloc : 'a -> t -> 'a loc
val print : Format.formatter -> t -> unit
val print_compact : Format.formatter -> t -> unit
val print_filename : Format.formatter -> string -> unit
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 absname : bool ref

Support for located errors

type error = Location.error = {
  1. loc : t;
  2. msg : string;
  3. sub : error list;
  4. if_highlight : string;
}
exception Already_displayed_error
exception Error of error
val error : ?loc:t -> ?sub:error list -> ?if_highlight:string -> string -> error
val errorf : ?loc:t -> ?sub:error list -> ?if_highlight:string -> ('a, Format.formatter, unit, error) format4 -> 'a
val raise_errorf : ?loc:t -> ?sub:error list -> ?if_highlight:string -> ('a, Format.formatter, unit, 'b) format4 -> 'a
val error_of_printer : t -> (Format.formatter -> 'a -> unit) -> 'a -> error
val error_of_printer_file : (Format.formatter -> 'a -> unit) -> 'a -> error
val error_of_exn : exn -> [ `Ok of error | `Already_displayed ] 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 : Format.formatter -> error -> unit
val error_reporter : (Format.formatter -> error -> unit) ref

Hook for intercepting error reports.

val default_error_reporter : Format.formatter -> error -> unit

Original error reporter for use in hooks.

val report_exception : Format.formatter -> exn -> unit

Reraise the exception if it is unknown.

val deprecated : ?def:t -> ?use:t -> t -> string -> unit
val format : Format.formatter -> t -> unit
val merge : t -> t -> t
OCaml

Innovation. Community. Security.