Module Import.Location

include module type of Ppxlib.Location

There are less functions in this module. However the API should be more stable than the Location module of OCaml.

For a detailled presentation of good practices regarding locations, refer to the section in the manual.

type t = Astlib.Location.t = {
  1. loc_start : Lexing.position;
  2. loc_end : Lexing.position;
  3. loc_ghost : bool;
}
val in_file : string -> t

Return an empty ghost range located in a given file.

val set_filename : t -> string -> t

Set the pos_fname both in loc_start and loc_end. Leave the rest as is.

val none : t

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

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 of_lexbuf : Lexing.lexbuf -> t

Return the location corresponding to the last matched regular expression

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

Report an exception on the given formatter

val print : Format.formatter -> t -> unit

Prints File "...", line ..., characters ...-...:

type nonrec 'a loc = 'a Astlib.Location.loc = {
  1. txt : 'a;
  2. loc : t;
}
val compare_pos : Lexing.position -> Lexing.position -> int
val compare : t -> t -> int
module Error = Ppxlib.Location.Error
val error_extensionf : loc:t -> ('a, Format.formatter, unit, string Astlib.Location.loc * Astlib.Ast_500.Parsetree.payload) format4 -> 'a

Returns an error extension node. When encountered in the AST, the compiler recognizes it and displays the error properly.

For a detailed explanation on error reporting, refer to the relevant part of the tutorial.

exception Error of Error.t
val raise_errorf : ?loc:location -> ('a, Format.formatter, unit, _) format4 -> 'a
  • alert do_not_raise Create an error node instead of raising. See [Location.error_extensionf], or alternately [Location.Error.createf] and [Location.Error.to_extension].