package b0

  1. Overview
  2. Docs
Software construction and deployment kit

Install

dune-project
 Dependency

Authors

Maintainers

Sources

b0-0.0.6.tbz
sha512=e9aa779e66c08fc763019f16d4706f465d16c05d6400b58fbd0313317ef33ddea51952e2b058db28e65f7ddb7012f328c8bf02d8f1da17bb543348541a2587f0

doc/b0.std/B0_text/Tloc/index.html

Module B0_text.TlocSource

Text locations.

Text locations

Sourcetype fpath = string

The type for file paths.

Sourceval no_file : fpath

no_file is Fpath.t "-", a path used when no file is specified.

Sourcetype pos = int

The type for zero-based, absolute, byte positions in text.

Sourcetype line = int

The type for one-based, line numbers in the text. Lines increment after a line feed '\n' (U+000A), a carriage return '\r' (U+000D) or a carriage return and a line feed "\r\n" (<U+000D,U+000A>).

Sourcetype line_pos = line * pos

The type for line positions. The line number and the byte position of the first element on the line. The later is the byte position after the newline which may not exist (at the end of file).

Sourcetype t

The type for text locations. A text location is a range of byte positions and the lines on which they occur in the UTF-8 encoded text of a particular file.

Sourceval v : file:fpath -> sbyte:pos -> ebyte:pos -> sline:line_pos -> eline:line_pos -> t

v ~file ~sbyte ~ebyte ~sline ~eline is a contructor for text locations. See corresponding accessors for the semantics. If you don't have a file use no_file.

Sourceval file : t -> fpath

file l is l's file.

Sourceval sbyte : t -> pos

sbyte l is l's start position.

Sourceval ebyte : t -> pos

ebyte l is l's end position.

Sourceval sline : t -> line_pos

sline l is the line position on which sbyte l lies.

Sourceval eline : t -> line_pos

elin l is the line position on which ebyte l lies.

Sourceval nil : t

loc_nil is an invalid location.

Sourceval merge : t -> t -> t

merge l0 l1 merges the location l0 and l1 to the smallest location that spans both location. The file path taken from l0.

Sourceval to_start : t -> t

to_start l has both start and end positions at l's start.

Sourceval to_end : t -> t

to_end l has both start and end positions at l's end.

Sourceval restart : at:t -> t -> t

restart ~at l is l with the start position of at.

Sourceval pp_ocaml : Format.formatter -> t -> unit

pp_ocaml formats location like the OCaml compiler.

Sourceval pp_gnu : Format.formatter -> t -> unit

pp_gnu formats location according to the GNU convention.

Sourceval pp : Format.formatter -> t -> unit

pp is pp_gnu.

Sourceval pp_dump : Format.formatter -> t -> unit

pp_dump formats raw data for debugging.

Substitutions and insertions

Strictly speaking this doesn't belong here but here you go.

Sourceval string_subrange : ?first:int -> ?last:int -> string -> string

string_subrange ~first ~last s are the consecutive bytes of s whose indices exist in the range [first;last].

first defaults to 0 and last to String.length s - 1.

Note that both first and last can be any integer. If first > last the interval is empty and the empty string is returned.

Sourceval string_replace : start:int -> stop:int -> rep:string -> string -> string

string_replace ~start ~stop ~rep s replaces the index range [start;stop-1] of s with rep as follows. If start = stop the rep is inserted before start. start and stop must be in range [0;String.length s] and start <= stop or Invalid_argument is raised.