module Loc: Camlp4.Sig.Loc
type
t
val mk : string -> t
Return a start location for the given file name.
This location starts at the begining of the file.
val ghost : t
The ghost
location can be used when no location
information is available.
Conversion functions
val of_lexing_position : Lexing.position -> t
Return a location where both positions are set the given position.
val to_ocaml_location : t -> Camlp4_import.Location.t
Return an OCaml location.
val of_ocaml_location : Camlp4_import.Location.t -> t
Return a location from an OCaml location.
val of_lexbuf : Lexing.lexbuf -> t
Return a location from ocamllex buffer.
val of_tuple : string * int * int * int * int * int * int * bool -> t
Return a location from (file_name, start_line, start_bol, start_off,
stop_line, stop_bol, stop_off, ghost)
.
val to_tuple : t -> string * int * int * int * int * int * int * bool
Return (file_name, start_line, start_bol, start_off,
stop_line, stop_bol, stop_off, ghost)
.
val merge : t -> t -> t
merge loc1 loc2
Return a location that starts at loc1
and end at loc2
.
val join : t -> t
The stop pos becomes equal to the start pos.
val move : [ `both | `start | `stop ] -> int -> t -> t
move selector n loc
Return the location where positions are moved.
Affected positions are chosen with selector
.
Returned positions have their character offset plus n
.
val shift : int -> t -> t
shift n loc
Return the location where the new start position is the old
stop position, and where the new stop position character offset is the
old one plus n
.
val move_line : int -> t -> t
move_line n loc
Return the location with the old line count plus n
.
The "begin of line" of both positions become the current offset.
Accessors
val file_name : t -> string
Return the file name
val start_line : t -> int
Return the line number of the begining of this location.
val stop_line : t -> int
Return the line number of the ending of this location.
val start_bol : t -> int
Returns the number of characters from the begining of the file
to the begining of the line of location's begining.
val stop_bol : t -> int
Returns the number of characters from the begining of the file
to the begining of the line of location's ending.
val start_off : t -> int
Returns the number of characters from the begining of the file
of the begining of this location.
val stop_off : t -> int
Return the number of characters from the begining of the file
of the ending of this location.
val start_pos : t -> Lexing.position
Return the start position as a Lexing.position.
val stop_pos : t -> Lexing.position
Return the stop position as a Lexing.position.
val is_ghost : t -> bool
Generally, return true if this location does not come
from an input stream.
val ghostify : t -> t
Return the associated ghost location.
val set_file_name : string -> t -> t
Return the location with the give file name
val strictly_before : t -> t -> bool
strictly_before loc1 loc2
True if the stop position of loc1
is
strictly_before the start position of loc2
.
val make_absolute : t -> t
Return the location with an absolute file name.
val print : Format.formatter -> t -> unit
Print the location into the formatter in a format suitable for error
reporting.
val dump : Format.formatter -> t -> unit
Print the location in a short format useful for debugging.
val to_string : t -> string
exception Exc_located of t * exn
Exc_located loc e
is an encapsulation of the exception e
with
the input location loc
. To be used in quotation expanders
and in grammars to specify some input location for an error.
Do not raise this exception directly: rather use the following
function Loc.raise
.
val raise : t -> exn -> 'a
raise loc e
, if e
is already an Exc_located
exception,
re-raise it, else raise the exception Exc_located loc e
.
val name : string Pervasives.ref
The name of the location variable used in grammars and in
the predefined quotations for OCaml syntax trees. Default: _loc
.