mirror of
https://github.com/ocaml-tracing/ocaml-opentelemetry.git
synced 2026-03-09 04:17:56 -04:00
2 lines
8.3 KiB
HTML
2 lines
8.3 KiB
HTML
<!DOCTYPE html>
|
||
<html xmlns="http://www.w3.org/1999/xhtml"><head><title>Buffered (angstrom.Angstrom.Buffered)</title><meta charset="utf-8"/><link rel="stylesheet" href="../../../_odoc-theme/odoc.css"/><meta name="generator" content="odoc 2.4.1"/><meta name="viewport" content="width=device-width,initial-scale=1.0"/><script src="../../../highlight.pack.js"></script><script>hljs.initHighlightingOnLoad();</script></head><body class="odoc"><nav class="odoc-nav"><a href="../index.html">Up</a> – <a href="../../index.html">angstrom</a> » <a href="../index.html">Angstrom</a> » Buffered</nav><header class="odoc-preamble"><h1>Module <code><span>Angstrom.Buffered</span></code></h1><p>Buffered parsing interface.</p><p>Parsers run through this module perform internal buffering of input. The parser state will keep track of unconsumed input and attempt to minimize memory allocation and copying. The <a href="#type-state.Partial"><code>Buffered.state.Partial</code></a> parser state will accept newly-read, incremental input and copy it into the internal buffer. Users can feed parser states using the <code>feed</code> function. As a result, the interface is much easier to use than the one exposed by the <a href="../Unbuffered/index.html"><code>Unbuffered</code></a> module.</p><p>On success or failure, any unconsumed input will be returned to the user for additional processing. The buffer that the unconsumed input is returned in can also be reused.</p></header><div class="odoc-content"><div class="odoc-spec"><div class="spec type anchored" id="type-unconsumed"><a href="#type-unconsumed" class="anchor"></a><code><span><span class="keyword">type</span> unconsumed</span><span> = </span><span>{</span></code><ol><li id="type-unconsumed.buf" class="def record field anchored"><a href="#type-unconsumed.buf" class="anchor"></a><code><span>buf : <a href="../index.html#type-bigstring">bigstring</a>;</span></code></li><li id="type-unconsumed.off" class="def record field anchored"><a href="#type-unconsumed.off" class="anchor"></a><code><span>off : int;</span></code></li><li id="type-unconsumed.len" class="def record field anchored"><a href="#type-unconsumed.len" class="anchor"></a><code><span>len : int;</span></code></li></ol><code><span>}</span></code></div></div><div class="odoc-spec"><div class="spec type anchored" id="type-input"><a href="#type-input" class="anchor"></a><code><span><span class="keyword">type</span> input</span><span> = </span><span>[ </span></code><ol><li id="type-input.Bigstring" class="def variant constructor anchored"><a href="#type-input.Bigstring" class="anchor"></a><code><span>| </span><span>`Bigstring <span class="keyword">of</span> <a href="../index.html#type-bigstring">bigstring</a></span></code></li><li id="type-input.String" class="def variant constructor anchored"><a href="#type-input.String" class="anchor"></a><code><span>| </span><span>`String <span class="keyword">of</span> string</span></code></li></ol><code><span> ]</span></code></div></div><div class="odoc-spec"><div class="spec type anchored" id="type-state"><a href="#type-state" class="anchor"></a><code><span><span class="keyword">type</span> <span>'a state</span></span><span> = </span></code><ol><li id="type-state.Partial" class="def variant constructor anchored"><a href="#type-state.Partial" class="anchor"></a><code><span>| </span><span><span class="constructor">Partial</span> <span class="keyword">of</span> <span><span>[ <a href="#type-input">input</a> <span>| `Eof</span> ]</span> <span class="arrow">-></span></span> <span><span class="type-var">'a</span> <a href="#type-state">state</a></span></span></code><div class="def-doc"><span class="comment-delim">(*</span><p>The parser requires more input.</p><span class="comment-delim">*)</span></div></li><li id="type-state.Done" class="def variant constructor anchored"><a href="#type-state.Done" class="anchor"></a><code><span>| </span><span><span class="constructor">Done</span> <span class="keyword">of</span> <a href="#type-unconsumed">unconsumed</a> * <span class="type-var">'a</span></span></code><div class="def-doc"><span class="comment-delim">(*</span><p>The parser succeeded.</p><span class="comment-delim">*)</span></div></li><li id="type-state.Fail" class="def variant constructor anchored"><a href="#type-state.Fail" class="anchor"></a><code><span>| </span><span><span class="constructor">Fail</span> <span class="keyword">of</span> <a href="#type-unconsumed">unconsumed</a> * <span>string list</span> * string</span></code><div class="def-doc"><span class="comment-delim">(*</span><p>The parser failed.</p><span class="comment-delim">*)</span></div></li></ol></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-parse"><a href="#val-parse" class="anchor"></a><code><span><span class="keyword">val</span> parse : <span><span class="optlabel">?initial_buffer_size</span>:int <span class="arrow">-></span></span> <span><span><span class="type-var">'a</span> <a href="../index.html#type-t">t</a></span> <span class="arrow">-></span></span> <span><span class="type-var">'a</span> <a href="#type-state">state</a></span></span></code></div><div class="spec-doc"><p><code>parse ?initial_buffer_size t</code> runs <code>t</code> and awaits input if needed. <code>parse</code> will allocate a buffer of size <code>initial_buffer_size</code> (defaulting to 4k bytes) to do input buffering and automatically grows the buffer as needed.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-feed"><a href="#val-feed" class="anchor"></a><code><span><span class="keyword">val</span> feed : <span><span><span class="type-var">'a</span> <a href="#type-state">state</a></span> <span class="arrow">-></span></span> <span><span>[ <a href="#type-input">input</a> <span>| `Eof</span> ]</span> <span class="arrow">-></span></span> <span><span class="type-var">'a</span> <a href="#type-state">state</a></span></span></code></div><div class="spec-doc"><p><code>feed state input</code> supplies the parser state with more input. If <code>state</code> is <code>Partial</code>, then parsing will continue where it left off. Otherwise, the parser is in a <code>Fail</code> or <code>Done</code> state, in which case the <code>input</code> will be copied into the state's buffer for later use by the caller.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-state_to_option"><a href="#val-state_to_option" class="anchor"></a><code><span><span class="keyword">val</span> state_to_option : <span><span><span class="type-var">'a</span> <a href="#type-state">state</a></span> <span class="arrow">-></span></span> <span><span class="type-var">'a</span> option</span></span></code></div><div class="spec-doc"><p><code>state_to_option state</code> returns <code>Some v</code> if the parser is in the <code>Done (bs, v)</code> state and <code>None</code> otherwise. This function has no effect on the current state of the parser.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-state_to_result"><a href="#val-state_to_result" class="anchor"></a><code><span><span class="keyword">val</span> state_to_result : <span><span><span class="type-var">'a</span> <a href="#type-state">state</a></span> <span class="arrow">-></span></span> <span><span>(<span class="type-var">'a</span>, string)</span> <a href="../../../ocaml/Stdlib/index.html#type-result">result</a></span></span></code></div><div class="spec-doc"><p><code>state_to_result state</code> returns <code>Ok v</code> if the parser is in the <code>Done (bs, v)</code> state and <code>Error msg</code> if it is in the <code>Fail</code> or <code>Partial</code> state.</p><p>This function has no effect on the current state of the parser.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-state_to_unconsumed"><a href="#val-state_to_unconsumed" class="anchor"></a><code><span><span class="keyword">val</span> state_to_unconsumed : <span><span><span class="type-var">_</span> <a href="#type-state">state</a></span> <span class="arrow">-></span></span> <span><a href="#type-unconsumed">unconsumed</a> option</span></span></code></div><div class="spec-doc"><p><code>state_to_unconsumed state</code> returns <code>Some bs</code> if <code>state = Done(bs, _)</code> or <code>state = Fail(bs, _, _)</code> and <code>None</code> otherwise.</p></div></div></div></body></html>
|