package pp_loc

  1. Overview
  2. Docs
Legend:
Library
Module
Module type
Parameter
Class
Class type

Abstraction over the input containing the input to read from.

type t

The abstract input type. Informally, an "input" of type t should support:

  • seeking the cursor to a given initial position (as a number of bytes)
  • from this position, read the input byte per byte

High-level functions

val file : string -> t

file fname is an input that corresponds to the content of the file named fname.

val string : string -> t

string s is an input that corresponds to the content of the string s.

val bytes : bytes -> t

bytes b is an input that corresponds to the content of the bytes array b.

Low-level functions

val raw : seek:(int -> (unit, [ `Invalid_position ]) Stdlib.result) -> read_char:(unit -> (char, [ `End_of_input ]) Stdlib.result) -> t

Creates an input from functions seek and read.

The function seek will be called once, before any call to read_char. If the call to seek fails and returns Error `Invalid_position, the input is considered to be unreadable and will be treated equivalenty as the empty input. This might happen even if the input is valid, if one tries to highlight an invalid location.

val managed : (unit -> t * (unit -> unit)) -> t

managed f enables creating an input which lifetime is managed explicitely. In other words, it handles inputs with explicit open and close operations.

For instance, a file (which needs to be explicitely opened then close) is an instance of managed.

If f() returns (i, c), then using the input managed f will first call f() to access the underlying input i, and will terminate by calling c ().

OCaml

Innovation. Community. Security.