Module Parsexp.Positions
Compact set of positions
type tA
tvalue represent a sequence of positions. The focus is on small memory footprint.Given a s-expression and a sequence of positions, one can reconstruct the location of every sub s-expression. This is used to report location informations without having to annotate every node in the s-expression during parsing.
The s-expression parser saves the positions of each opening and closing parentheses as well as the positions of the first and last character of each atom.
Note that a
tcan hold the same given positions no more than twice. The parser stores the same position twice for non-quoted single character atoms.
val sexp_of_t : t -> Parsexp__.Import.Ppx_sexp_conv_lib.Sexp.tval compare : t -> t -> int
type pos={line : int;Line number. The first line has number
1.col : int;Column number. The first column has number
0.offset : int;Number of bytes from the beginning of the input. The first byte has offset
0.}Represent a position in the input
val sexp_of_pos : pos -> Parsexp__.Import.Ppx_sexp_conv_lib.Sexp.tval compare_pos : pos -> pos -> int
type range={start_pos : pos;end_pos : pos;}Range of positions, as reported in error messages. We follow the lexing conventions of OCaml, i.e.
start_pospoints to the first character andend_pospoints to the position just after the last character.This allow for instance to represent empty ranges with
start_pos = end_pos.
val sexp_of_range : range -> Parsexp__.Import.Ppx_sexp_conv_lib.Sexp.tval compare_range : range -> range -> int
val make_range_incl : start_pos:pos -> last_pos:pos -> rangeMake a range from two positions where both positions are inclusive, i.e.
start_pospoints to the first character andend_pospoints to the last one. The character atlast_posis assumed to not be a newline character.
val find : t -> int -> int -> rangefind t start stopreturns the range of positions starting at position with indexstartintand ending at position with indexstop.find t i jis the same as:let a = to_array t in make_range_incl ~start_pos:a.(i) ~last_pos:a.(j)but more efficient.
val find_sub_sexp_phys : t -> Parsexp__.Import.Ppx_sexp_conv_lib.Sexp.t -> sub:Parsexp__.Import.Ppx_sexp_conv_lib.Sexp.t -> range optionfind_sub_sexp_phys t sexp ~sublooks forsubinsexpand return its location, assumingtis the sequence of positions associated withsexp.Comparison is done using physical equality.
val find_sub_sexp_in_list_phys : t -> Parsexp__.Import.Ppx_sexp_conv_lib.Sexp.t list -> sub:Parsexp__.Import.Ppx_sexp_conv_lib.Sexp.t -> range optionval memory_footprint_in_bytes : t -> intReturns how much memory is used by
t