package parseff
Install
dune-project
Dependency
Authors
Maintainers
Sources
sha256=133646bafed8921551767b27ab01aed3106b5c1eaadc86133357901c16ebc5e2
sha512=6da046fdb320999fbc244ea01e02e54c451d926f8bc7cf6a8036b0e576a622d35780712f59aae1e4d6f386289b0040f588123e2ac8290a0e505caf66ff9a94eb
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 through the effect handler; existing parser code works unchanged.
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).
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.
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)