Page
Library
Module
Module type
Parameter
Class
Class type
Source
Loc
SourceA library to manipulate code locations, typically to decorate AST nodes built by parser so as to allow located error messages.
An immutable value representing a range of characters in a file.
By default, locations are hidden and rendered as the Atom "_"
. Locations are typically brittle, and not always interesting when inspecting the nodes of an AST. You may however set include_sexp_of_locs
to true
- then sexp_of_t
will show actual locations.
By default set to false
, this may be temporarily turned to true
to inspect locations in the dump of an AST.
equal t1 t2
returns true
if t1 and t2 identify the same location. Beware, it is possible to deactivate comparison of locs by setting equal_ignores_locs
to true
, in which case equal
will always return true
.
By default set to false
, this may be temporarily turned to true
to operates some comparison that ignores all locations. When this is true
, equal
returns true
for any locs.
To be called in the right hand side of a Menhir rule, using the $loc
special keyword provided by Menhir. For example:
ident: | ident=IDENT { Loc.create $loc } ;
To be used with a Lexing.position
, including for example:
Loc.of_position [%here]
To be used with the __POS__
special construct. For example:
Loc.of_pos __POS__
Build a location from the current internal state of the lexbuf
.
Build a location identifying the file as a whole. This is a practical location to use when it is not possible to build a more precise location rather than the entire file.
When locations are created manually, such as from a given line number, to compute all the actual positions and offsets we need to access the original contents of the file and locate new lines characters in it. This cache serves this purpose.
Create a location that covers the entire line line
of the file. Lines start at 1
. Raises Invalid_argument
if the line overflows.
Build the first line of error messages to produce to stderr using the same syntax as used by the OCaml compiler. If your editor has logic to recognize it, it will allow to jump to the source file.
This builds a short string representation for use in tests or quick debug.
Retrieve the line number from the start position of the given location. Line numbers start at line 1.
Convert between Lexbuf_loc
and t
.
Access the start
(included) and stop
(excluded) positions of a location, expressed as lexing positions.