Module Pos

Source code position management. This module can be used to map the elements of an abstract syntax tree to sequences of characters in a source file.

type pos = {
fname : string option;(*

File name associated to the position.

*)
start_line : int;(*

Line number of the starting point.

*)
start_col : int;(*

Column number (utf8) of the starting point.

*)
end_line : int;(*

Line number of the ending point.

*)
end_col : int;(*

Column number (utf8) of the ending point.

*)
}

Type of a position corresponding to a continuous range of characters in a (utf8 encoded) source file.

type popt = pos option

Convenient short name for an optional position.

type 'a loc = {
elt : 'a;(*

The element that is being localised.

*)
pos : popt;(*

Position of the element in the source code.

*)
}

Type constructor extending a type (e.g. an element of an abstract syntax tree) with a source code position.

type strloc = string loc

Localised string type (widely used).

val make : popt -> 'a -> 'a loc

make pos elt associates the position pos to elt.

val in_pos : pos -> 'a -> 'a loc

in_pos pos elt associates the position pos to elt.

val none : 'a -> 'a loc

none elt wraps elt in a localisation structure with no specified source position.

val merge : pos -> pos -> pos
val union : popt -> popt -> popt
val locate : Earley_core.Input.buffer -> int -> Earley_core.Input.buffer -> int -> pos

locate buf1 pos1 buf2 pos2 builds a position structure given two DeCaP input buffers. This function can be used by DeCaP to generate the position of elements during parsing.

val pos_to_string : pos -> string

pos_to_string pos transforms the position pos into a readable format.

val print_pos : Stdlib.out_channel -> pos -> unit

print_pos oc pos prints the position pos to the channel oc.

val short_pos_to_string : pos -> string

short_pos_to_string pos is similar to pos_to_string pos but uses a shorter format.

val print_short_pos : Stdlib.out_channel -> pos -> unit

print_short_pos oc pos prints the position pos to the channel oc using a shorter format that print_pos oc pos.