val parse_exn :
?initial_size:int ->max_size:int ->'aparser->_Flow.source->'a
parse_exn wraps parse, but raises Failure msg if that returns Error (`Msg msg).
Catching exceptions with parse and then raising them might seem pointless, but this has the effect of turning e.g. an End_of_file exception into a Failure with a more user-friendly message.
val parse_string :
'aparser->string ->('a, [> `Msg of string ])Stdlib.result
parse_string p s uses p to parse everything in s. It is defined as format_errors (p <* end_of_input) (of_string s)
val of_flow : ?initial_size:int ->max_size:int ->_Flow.source->t
of_flow ~max_size flow is a buffered reader backed by flow.
parameterinitial_size
The initial amount of memory to allocate for the buffer.
parametermax_size
The maximum size to which the buffer may grow. This must be large enough to hold the largest single item you want to parse (e.g. the longest line, if using line), plus any terminator needed to know the value is complete (e.g. the newline character(s)). This is just to prevent a run-away input from consuming all memory, and you can usually just set it much larger than you expect to need.
of_buffer buf is a reader that reads from buf. buf is used directly, without being copied. eof_seen (of_buffer buf) = true. This module will not modify buf itself, but it will expose it via peek.
seq p is a sequence that uses p to get the next item.
A sequence node can only be used while the stream is at the expected position, and will raise Invalid_argument if any bytes have been consumed in the meantime. This also means that each node can only be used once; use Seq.memoize to make the sequence persistent.
It is not necessary to consume all the elements of the sequence.
Example (head 4 is a parser that takes 4 lines):
let head n r =
r |> Buf_read.(seq line) |> Seq.take n |> List.of_seq
parameterstop
This is used before parsing each item. The sequence ends if this returns true. The default is at_end_of_input.