package grace

  1. Overview
  2. Docs

A source reader maintains a global table mapping source descriptors to their contents and their line starts.

module Source_descr : sig ... end

A source descriptor is a handle for an open source

module Line_starts : sig ... end
type error = [
  1. | `Already_initialized
  2. | `Not_initialized
]
exception Error of error
val init : ?line_starts_fn:Line_starts.fn -> unit -> unit

init () initializes the global source reader table.

  • parameter line_starts_fn

    the line starts function used for computing line starts.

  • raises Source_reader.Error

    if the reader is already initialized.

val clear : unit -> unit

clear () clears the global source reader table.

val with_reader : ?line_starts_fn:Line_starts.fn -> (unit -> 'a) -> 'a

with_reader f runs f with an initialized reader table, clearing it once f returns.

  • parameter line_starts_fn

    the line starts function used for computing line starts.

  • raises Source_reader.Error

    if the reader is already initialized.

val open_source : Grace.Source.t -> Source_descr.t

open_source src opens the source, returning its descriptor.

  • raises Source_reader.Error

    if the reader is not initialized.

val line_starts : Source_descr.t -> Line_starts.t

line_starts sd returns the (possibly cached) line starts of the source sd.

  • raises Source_reader.Error

    if the reader is not initialized.

val length : Source_descr.t -> int

length sd returns the length or size in bytes of src.

It is semantically equivalent to Source.length src.

val unsafe_get : Source_descr.t -> int -> char

unsafe_get sd i reads the ith byte of the source without performing any bounds checks on i.

val slice : Source_descr.t -> Grace.Range.t -> string

slice sd range reads the slice of bytes defined by range.

  • raises Invalid_argment

    if the source descriptor's underlying source is not equal to the range's source.

module Line : sig ... end
val lines : Source_descr.t -> Line.t Iter.t

lines sd returns an iterator over lines in source sd.

val lines_in_range : Source_descr.t -> Grace.Range.t -> Line.t Iter.t

lines_in_range sd range returns an iterator over lines in the range in sd.

  • raises Invalid_argment

    if the source descriptor's underlying source is not equal to the line range's source.

OCaml

Innovation. Community. Security.