Module 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.

type t

The type of character positions in a source file.

Constructors

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.

Destructors

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

Instances

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
val compare : t -> t -> int

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:

  • Comparability: (compare a b <= 0 || compare b a >= 0) = true,
  • Transitivity: if (compare a b <= 0) = true and (compare b c <= 0) = true, then (compare a c <= 0) = true,
  • Reflexivity: (compare a a = 0) = true,
  • Antisymmetry: if (compare a b <= 0) = true and (compare a b >= 0) = true then (compare a b = 0) = true.
val (<) : t -> t -> bool
val (<=) : t -> t -> bool
val (>) : t -> t -> bool
val (>=) : t -> t -> bool
val max : t -> t -> t

max a b is a if a >= b and b otherwise.

val min : t -> t -> t

min a b is a if a <= b and b otherwise.

include Support.Eq.EQ with type t := t
val equal : t -> t -> bool

equal a b is true if and only if a and b are equal. This should satisfy the following properties:

  • Reflexivity: equal a a = true
  • Symmetry: equal a b is equivalent to equal b a
  • Transitivity: if equal a b = true and equal b c = true, then equal a c = true
val (=) : t -> t -> bool

Operator alias of equal.

val (<>) : t -> t -> bool

Negation of operator (=).

Interoperability

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.