Abstraction over the input containing the input to read from.
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
val file : string -> t
file fname is an input that corresponds to the content of the file named
val string : string -> t
string s is an input that corresponds to the content of the string
val bytes : bytes -> t
bytes b is an input that corresponds to the content of the bytes array
val in_channel : in_channel -> t
in_channel cin is an input that correspond to the input channel
cin. The channel must correspond to a file: it must be possible to call
seek_in on the channel without error.
Creating an input using
in_channel instead of
file is more efficient if one needs to perform successive calls of
Pp_loc.pp on the same input. Otherwise (or if having the best performance is not important), it is simpler (and thus recommended) to use
val raw : seek:(int -> (unit, [ `Invalid_position ]) result) -> read_char:(unit -> (char, [ `End_of_input ]) result) -> line_offsets:(unit -> int array) -> t
Creates an input from functions.
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
(i, c), then using the input
managed f will first call
f() to access the underlying input
i, and will terminate by calling