Syncom.Position
Character positions in source files.
The definition for a character position depends on the source file's encoding. A lexer is typically responsible for constructing positions.
val make : line:int -> beginning_of_line:int -> offset:int -> t
make ~line ~beginning_of_line ~offset
is the source code position at a character distance offset
from the initial position of a file. line
is the number of the line (starting at 1) in which the character occurs. beginning_of_line
is the character distance from the initial position of the file and the beginning of the line.
The character distances have to be computed with respect to the file's encoding. UTF-8, the default encoding for Beluga signatures, is a variable-width encoding, so it is incorrect to always count a byte as a character.
val initial : t
initial
is the initial position of a character in a source file, with line initial = 1
, beginning_of_line initial = 0
and offset initial = 0
.
val line : t -> int
line position
is the line of position
. The line count starts at 1
.
val column : t -> int
column position
is the column of position
, computed from its beginning of line and actual offsets. The column count starts at 1
.
val beginning_of_line : t -> int
val offset : t -> int
Equality of positions by their offsets.
include Support.Eq.EQ with type t := t
Total ordering of positions by their offsets.
include Support.Ord.ORD with type t := t
compare a b
compares a
and b
for ordering.
compare a b < 0
if a
precedes b
(denoted a < b
),compare a b = 0
if a
is equal to b
(denoted a = b
),compare a b > 0
if a
succeeds b
(denoted a > b
).This should satisfy the following properties:
(compare a b <= 0 || compare b a >= 0) = true
,(compare a b <= 0) = true
and (compare b c <= 0) = true
, then (compare a c <= 0) = true
,(compare a a = 0) = true
,(compare a b <= 0) = true
and (compare a b >= 0) = true
then (compare a b = 0) = true
.include Support.Eq.EQ with type t := t
equal a b
is true
if and only if a
and b
are equal. This should satisfy the following properties:
equal a a = true
equal a b
is equivalent to equal b a
equal a b = true
and equal b c = true
, then equal a c = true
val make_from_lexing_position : Stdlib.Lexing.position -> t
make_from_lexing_position lexing_position
is the character position derived from lexing_position
using its pos_lnum
, pos_bol
and pos_cnum
.
val to_lexing_position : ?filename:string -> t -> Stdlib.Lexing.position
to_lexing_position ?filename position
is the lexing position derived from position
with filename
as pos_fname
if it is defined, and ""
otherwise.