Syncom.Location
Character position ranges in source files.
A parser is typically responsible for constructing locations using positions generated by the lexer.
val ghost : t
ghost
is the null location used for AST nodes having no correspondence to a source file.
val initial : string -> t
initial filename
is the location at the beginning of the file with name filename
.
val make :
filename:string ->
start_position:Position.t ->
stop_position:Position.t ->
t
make ~filename ~start_position ~stop_position
is the non-ghost location starting at the character position start_position
inclusively and ending at the character position stop_position
exclusively in the file at filename
.
join l1 l2
is the smallest location that contains l1
and l2
.
It is assumed that filename l1 = filename l2
.
Ghost locations are left and right identities of join
, meaning that:
is_ghost l1
, then join l1 l2 = l2
.is_ghost l2
, then join l1 l2 = l1
.val join_all : t -> t Support.List.t -> t
join_all init ls
is each location in ls
joined together, additionally with init
.
val join_all_contramap : ('a -> t) -> t -> 'a Support.List.t -> t
join_all_contramap f init xs
is each location contramapped by f
from xs
. joined together, additionally with init
.
If xs = [x1; x2; ...; xn]
, then join_all_contramap f init xs = join_all init [f x1; f x2; ...; f xn]
.
val join_all1 : t Support.List1.t -> t
val join_all1_contramap : ('a -> t) -> 'a Support.List1.t -> t
val join_all2_contramap : ('a -> t) -> 'a Support.List2.t -> t
val set_start : Position.t -> t -> t
val set_stop : Position.t -> t -> t
set_start_line line location
is location
with its start line set to line
. The start position's beginning of line and offset are not modified, so the output location may be invalid. This should only be used with locations that do not point to files, like ghost locations.
set_stop_line line location
is like set_start_line line location
but for the location's stop position.
val filename : t -> string
val start_position : t -> Position.t
val stop_position : t -> Position.t
val start_offset : t -> int
val stop_offset : t -> int
val start_bol : t -> int
val stop_bol : t -> int
val start_line : t -> int
val stop_line : t -> int
val start_column : t -> int
val stop_column : t -> int
val spanned_offsets : t -> int
spanned_offsets location
is stop_offset location - start_offset location
.
val is_ghost : t -> bool
module Ord_by_start : Support.Ord.ORD with type t = t
module Ord_by_stop : Support.Ord.ORD with type t = t
val print : Support.Format.formatter -> t -> unit
Prints `<filename>, line <n>, column <n>'. Suitable for proper errors.
val pp : Support.Format.formatter -> t -> unit
val print_short : Support.Format.formatter -> t -> unit
Prints `line <n>, column <n>'. More suitable for debug prints.
val print_span_short : Support.Format.formatter -> t -> unit
Prints `<n>.<n> - <n>.<n>' indicating start and stop positions.
val make_from_lexing_positions :
filename:string ->
start_position:Stdlib.Lexing.position ->
stop_position:Stdlib.Lexing.position ->
t
val start_to_lexing_position : t -> Stdlib.Lexing.position
val stop_to_lexing_position : t -> Stdlib.Lexing.position
val to_lexing_positions : t -> Stdlib.Lexing.position * Stdlib.Lexing.position
Structural equality instance.
include Support.Eq.EQ with type t := t
Lexicographical ordering instance by filename, start position and stop position in that sequence.
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