package dolmen

  1. Overview
  2. Docs

Standard implementation of file locations.

Interface definition

module type S = Dolmen_intf.Location.S

An anstract module type for providing locations. Used as argumentby much of the functors provided in Dolmen. This module (ParseLocation) implements this specification.

Concrete positions

type t = {
  1. file : string;
  2. start_line : int;
  3. start_column : int;
  4. stop_line : int;
  5. stop_column : int;
}
exception Uncaught of t * exn
exception Lexing_error of t * string
exception Syntax_error of t * string

Exceptions that may occur during parsing

val hash : t -> int
val eq : t -> t -> bool

Hash and equality

val mk : string -> int -> int -> int -> int -> t
val mk_pair : string -> (int * int) -> (int * int) -> t
val mk_pos : Lexing.position -> Lexing.position -> t

Construction functions

val pp : Buffer.t -> t -> unit
val fmt : Format.formatter -> t -> unit
val fmt_hint : Format.formatter -> t -> unit

Printing functions

val combine : t -> t -> t

Location that spans the two given positions. The file is assumed to be the same in both case, and is chosen from one of the two positions.

val combine_list : t list -> t

N-ary version of combine.

  • raises Invalid_argument

    if the list is empty

val smaller : t -> t -> bool

smaller p1 p2 is true if p1 is included in p2, ie p1 is a sub-location of p2 (interval inclusion)

Lexbuf

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

Change the file name used for positions in this lexbuf

val mk_lexbuf : [ `Stdin | `File of string ] -> Lexing.lexbuf * (unit -> unit)

Returns the lexbuf associetd with the given file or stdin, with the correct filename, together with a function to close the associated file descriptor.

val of_lexbuf : Lexing.lexbuf -> t

Recover a position from a lexbuf