package parseff
All checked builds passInstall
dune-project
Dependency
Authors
Maintainers
Sources
sha256=dad671e98bdf1816c76a5e61da157bf38a986057ed2f9416573143bb8f1afcce
sha512=2ac03f296c73611ff6905e29c6c7df5bc3319933dbe3525a165d28f1dd56d4af4db5a0093b0d805064dc310322cef4e8b03ba1b2faf8890af2f202552e8ed2d7
doc/parseff/Parseff/Source/index.html
Module Parseff.SourceSource
Input sources for incremental parsing. A source wraps a readable byte stream — a channel, file descriptor, or custom reader — behind a uniform interface. The parser pulls data on demand by calling the source's read function; existing parser code works unchanged.
A source is for one parse. of_string starts again from the beginning, but the other sources continue where the last read stopped, and bytes that the first parse read ahead are lost.
of_string s creates a source from a complete string. Useful for testing streaming code paths with known input.
of_channel ?buf_size ic creates a source that reads from ic. buf_size controls the internal read buffer (default 4096). Raises Invalid_argument if buf_size is less than 1.
of_function read creates a source that calls read buf off len to obtain up to len bytes starting at offset off in buf. Must return the number of bytes actually read; return 0 to signal EOF. A result outside 0..len raises Invalid_argument from the parse.
This is the low-level escape hatch for byte sources that fill a pre-allocated buffer, such as Unix.read or Unix.recv. For most use cases, prefer of_chunks or of_seq.
of_chunks read creates a source that calls read () to obtain the next chunk of input. Return Some s with a non-empty string for data, or None to signal EOF. Empty strings (Some "") are silently skipped.
This is the recommended way to wrap effectful or callback-based data sources:
(* Eio promise *)
let fetched = ref false in
let source = Source.of_chunks (fun () ->
if !fetched then None
else begin
fetched := true;
Some (Promise.await_exn promise)
end)