ocaml-containers/3.0/containers/CCParse/index.html
2020-07-28 18:27:01 -04:00

27 lines
No EOL
28 KiB
HTML
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"><head><title>CCParse (containers.CCParse)</title><link rel="stylesheet" href="../../odoc.css"/><meta charset="utf-8"/><meta name="viewport" content="width=device-width,initial-scale=1.0"/><script src="../../highlight.pack.js"></script><script>hljs.initHighlightingOnLoad();</script></head><body><div class="content"><header><nav><a href="../index.html">Up</a> <a href="../index.html">containers</a> &#x00BB; CCParse</nav><h1>Module <code>CCParse</code></h1><h2 id="very-simple-parser-combinators"><a href="#very-simple-parser-combinators" class="anchor"></a>Very Simple Parser Combinators</h2><pre><code class="ml">open CCParse;;
type tree = L of int | N of tree * tree;;
let mk_leaf x = L x
let mk_node x y = N(x,y)
let ptree = fix @@ fun self -&gt;
skip_space *&gt;
( (try_ (char '(') *&gt; (pure mk_node &lt;*&gt; self &lt;*&gt; self) &lt;* char ')')
&lt;|&gt;
(U.int &gt;|= mk_leaf) )
;;
parse_string_exn ptree &quot;(1 (2 3))&quot; ;;
parse_string_exn ptree &quot;((1 2) (3 (4 5)))&quot; ;;</code></pre><h5 id="parse-a-list-of-words"><a href="#parse-a-list-of-words" class="anchor"></a>Parse a list of words</h5><pre><code class="ml">open Containers.Parse;;
let p = U.list ~sep:&quot;,&quot; U.word;;
parse_string_exn p &quot;[abc , de, hello ,world ]&quot;;;</code></pre><h5 id="stress-test"><a href="#stress-test" class="anchor"></a>Stress Test</h5><p>This makes a list of 100_000 integers, prints it and parses it back.</p><pre><code class="ml">let p = CCParse.(U.list ~sep:&quot;,&quot; U.int);;
let l = CCList.(1 -- 100_000);;
let l_printed =
CCFormat.(to_string (within &quot;[&quot; &quot;]&quot; (list ~sep:(return &quot;,@,&quot;) int))) l;;
let l' = CCParse.parse_string_exn p l_printed;;
assert (l=l');;</code></pre><nav class="toc"><ul><li><a href="#input">Input</a></li><li><a href="#combinators">Combinators</a></li><li><a href="#parse">Parse</a></li><li><a href="#infix">Infix</a></li><li><a href="#utils">Utils</a></li></ul></nav></header><dl><dt class="spec type" id="type-or_error"><a href="#type-or_error" class="anchor"></a><code><span class="keyword">type</span> 'a or_error</code><code> = (<span class="type-var">'a</span>, string) Stdlib.result</code></dt><dt class="spec type" id="type-line_num"><a href="#type-line_num" class="anchor"></a><code><span class="keyword">type</span> line_num</code><code> = int</code></dt><dt class="spec type" id="type-col_num"><a href="#type-col_num" class="anchor"></a><code><span class="keyword">type</span> col_num</code><code> = int</code></dt><dt class="spec type" id="type-parse_branch"><a href="#type-parse_branch" class="anchor"></a><code><span class="keyword">type</span> parse_branch</code></dt></dl><dl><dt class="spec value" id="val-string_of_branch"><a href="#val-string_of_branch" class="anchor"></a><code><span class="keyword">val</span> string_of_branch : <a href="index.html#type-parse_branch">parse_branch</a> <span>&#45;&gt;</span> string</code></dt></dl><dl><dt class="spec exception" id="exception-ParseError"><a href="#exception-ParseError" class="anchor"></a><code><span class="keyword">exception</span> </code><code><span class="exception">ParseError</span> <span class="keyword">of</span> <a href="index.html#type-parse_branch">parse_branch</a> * unit <span>&#45;&gt;</span> string</code></dt><dd><p>parsing branch * message.</p></dd></dl><section><header><h3 id="input"><a href="#input" class="anchor"></a>Input</h3></header><dl><dt class="spec type" id="type-position"><a href="#type-position" class="anchor"></a><code><span class="keyword">type</span> position</code></dt><dt class="spec type" id="type-state"><a href="#type-state" class="anchor"></a><code><span class="keyword">type</span> state</code></dt></dl><dl><dt class="spec value" id="val-state_of_string"><a href="#val-state_of_string" class="anchor"></a><code><span class="keyword">val</span> state_of_string : string <span>&#45;&gt;</span> <a href="index.html#type-state">state</a></code></dt></dl></section><section><header><h3 id="combinators"><a href="#combinators" class="anchor"></a>Combinators</h3></header><dl><dt class="spec type" id="type-t"><a href="#type-t" class="anchor"></a><code><span class="keyword">type</span> 'a t</code><code> = <a href="index.html#type-state">state</a> <span>&#45;&gt;</span> ok:(<span class="type-var">'a</span> <span>&#45;&gt;</span> unit) <span>&#45;&gt;</span> err:(exn <span>&#45;&gt;</span> unit) <span>&#45;&gt;</span> unit</code></dt><dd><p>Takes the input and two continuations:</p><ul><li><code>ok</code> to call with the result when it's done</li><li><code>err</code> to call when the parser met an error</li></ul><dl><dt>raises ParseError</dt><dd><p>in case of failure.</p></dd></dl></dd></dl><dl><dt class="spec value" id="val-return"><a href="#val-return" class="anchor"></a><code><span class="keyword">val</span> return : <span class="type-var">'a</span> <span>&#45;&gt;</span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a></code></dt><dd><p>Always succeeds, without consuming its input.</p></dd></dl><dl><dt class="spec value" id="val-pure"><a href="#val-pure" class="anchor"></a><code><span class="keyword">val</span> pure : <span class="type-var">'a</span> <span>&#45;&gt;</span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a></code></dt><dd><p>Synonym to <a href="index.html#val-return"><code>return</code></a>.</p></dd></dl><dl><dt class="spec value" id="val-(&gt;|=)"><a href="#val-(&gt;|=)" class="anchor"></a><code><span class="keyword">val</span> (&gt;|=) : <span class="type-var">'a</span> <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> (<span class="type-var">'a</span> <span>&#45;&gt;</span> <span class="type-var">'b</span>) <span>&#45;&gt;</span> <span class="type-var">'b</span> <a href="index.html#type-t">t</a></code></dt><dd><p>Map.</p></dd></dl><dl><dt class="spec value" id="val-map"><a href="#val-map" class="anchor"></a><code><span class="keyword">val</span> map : (<span class="type-var">'a</span> <span>&#45;&gt;</span> <span class="type-var">'b</span>) <span>&#45;&gt;</span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> <span class="type-var">'b</span> <a href="index.html#type-t">t</a></code></dt><dt class="spec value" id="val-map2"><a href="#val-map2" class="anchor"></a><code><span class="keyword">val</span> map2 : (<span class="type-var">'a</span> <span>&#45;&gt;</span> <span class="type-var">'b</span> <span>&#45;&gt;</span> <span class="type-var">'c</span>) <span>&#45;&gt;</span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> <span class="type-var">'b</span> <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> <span class="type-var">'c</span> <a href="index.html#type-t">t</a></code></dt><dt class="spec value" id="val-map3"><a href="#val-map3" class="anchor"></a><code><span class="keyword">val</span> map3 : (<span class="type-var">'a</span> <span>&#45;&gt;</span> <span class="type-var">'b</span> <span>&#45;&gt;</span> <span class="type-var">'c</span> <span>&#45;&gt;</span> <span class="type-var">'d</span>) <span>&#45;&gt;</span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> <span class="type-var">'b</span> <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> <span class="type-var">'c</span> <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> <span class="type-var">'d</span> <a href="index.html#type-t">t</a></code></dt><dt class="spec value" id="val-(&gt;&gt;=)"><a href="#val-(&gt;&gt;=)" class="anchor"></a><code><span class="keyword">val</span> (&gt;&gt;=) : <span class="type-var">'a</span> <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> (<span class="type-var">'a</span> <span>&#45;&gt;</span> <span class="type-var">'b</span> <a href="index.html#type-t">t</a>) <span>&#45;&gt;</span> <span class="type-var">'b</span> <a href="index.html#type-t">t</a></code></dt><dd><p>Monadic bind. <code>p &gt;&gt;= f</code> results in a new parser which behaves as <code>p</code> then, in case of success, applies <code>f</code> to the result.</p></dd></dl><dl><dt class="spec value" id="val-(&lt;*&gt;)"><a href="#val-(&lt;*&gt;)" class="anchor"></a><code><span class="keyword">val</span> (&lt;*&gt;) : (<span class="type-var">'a</span> <span>&#45;&gt;</span> <span class="type-var">'b</span>) <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> <span class="type-var">'b</span> <a href="index.html#type-t">t</a></code></dt><dd><p>Applicative.</p></dd></dl><dl><dt class="spec value" id="val-(&lt;*)"><a href="#val-(&lt;*)" class="anchor"></a><code><span class="keyword">val</span> (&lt;*) : <span class="type-var">'a</span> <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> <span class="type-var">_</span> <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a></code></dt><dd><p><code>a &lt;* b</code> parses <code>a</code> into <code>x</code>, parses <code>b</code> and ignores its result, and returns <code>x</code>.</p></dd></dl><dl><dt class="spec value" id="val-(*&gt;)"><a href="#val-(*&gt;)" class="anchor"></a><code><span class="keyword">val</span> (*&gt;) : <span class="type-var">_</span> <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a></code></dt><dd><p><code>a *&gt; b</code> parses <code>a</code>, then parses <code>b</code> into <code>x</code>, and returns <code>x</code>. The results of <code>a</code> is ignored.</p></dd></dl><dl><dt class="spec value" id="val-fail"><a href="#val-fail" class="anchor"></a><code><span class="keyword">val</span> fail : string <span>&#45;&gt;</span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a></code></dt><dd><p><code>fail msg</code> fails with the given message. It can trigger a backtrack.</p></dd></dl><dl><dt class="spec value" id="val-failf"><a href="#val-failf" class="anchor"></a><code><span class="keyword">val</span> failf : (<span class="type-var">'a</span>, unit, string, <span class="type-var">'b</span> <a href="index.html#type-t">t</a>) Stdlib.format4 <span>&#45;&gt;</span> <span class="type-var">'a</span></code></dt><dd><p><code>Format.sprintf</code> version of <a href="index.html#val-fail"><code>fail</code></a>.</p></dd></dl><dl><dt class="spec value" id="val-parsing"><a href="#val-parsing" class="anchor"></a><code><span class="keyword">val</span> parsing : string <span>&#45;&gt;</span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a></code></dt><dd><p><code>parsing s p</code> behaves the same as <code>p</code>, with the information that we are parsing <code>s</code>, if <code>p</code> fails.</p></dd></dl><dl><dt class="spec value" id="val-eoi"><a href="#val-eoi" class="anchor"></a><code><span class="keyword">val</span> eoi : unit <a href="index.html#type-t">t</a></code></dt><dd><p>Expect the end of input, fails otherwise.</p></dd></dl><dl><dt class="spec value" id="val-nop"><a href="#val-nop" class="anchor"></a><code><span class="keyword">val</span> nop : unit <a href="index.html#type-t">t</a></code></dt><dd><p>Succeed with <code>()</code>.</p></dd></dl><dl><dt class="spec value" id="val-char"><a href="#val-char" class="anchor"></a><code><span class="keyword">val</span> char : char <span>&#45;&gt;</span> char <a href="index.html#type-t">t</a></code></dt><dd><p><code>char c</code> parses the character <code>c</code> and nothing else.</p></dd></dl><dl><dt class="spec value" id="val-char_if"><a href="#val-char_if" class="anchor"></a><code><span class="keyword">val</span> char_if : (char <span>&#45;&gt;</span> bool) <span>&#45;&gt;</span> char <a href="index.html#type-t">t</a></code></dt><dd><p><code>char_if f</code> parses a character <code>c</code> if <code>f c = true</code>.</p></dd></dl><dl><dt class="spec value" id="val-chars_if"><a href="#val-chars_if" class="anchor"></a><code><span class="keyword">val</span> chars_if : (char <span>&#45;&gt;</span> bool) <span>&#45;&gt;</span> string <a href="index.html#type-t">t</a></code></dt><dd><p><code>chars_if f</code> parses a string of chars that satisfy <code>f</code>.</p></dd></dl><dl><dt class="spec value" id="val-chars1_if"><a href="#val-chars1_if" class="anchor"></a><code><span class="keyword">val</span> chars1_if : (char <span>&#45;&gt;</span> bool) <span>&#45;&gt;</span> string <a href="index.html#type-t">t</a></code></dt><dd><p>Like <a href="index.html#val-chars_if"><code>chars_if</code></a>, but only non-empty strings.</p></dd></dl><dl><dt class="spec value" id="val-endline"><a href="#val-endline" class="anchor"></a><code><span class="keyword">val</span> endline : char <a href="index.html#type-t">t</a></code></dt><dd><p>Parse '\n'.</p></dd></dl><dl><dt class="spec value" id="val-space"><a href="#val-space" class="anchor"></a><code><span class="keyword">val</span> space : char <a href="index.html#type-t">t</a></code></dt><dd><p>Tab or space.</p></dd></dl><dl><dt class="spec value" id="val-white"><a href="#val-white" class="anchor"></a><code><span class="keyword">val</span> white : char <a href="index.html#type-t">t</a></code></dt><dd><p>Tab or space or newline.</p></dd></dl><dl><dt class="spec value" id="val-skip_chars"><a href="#val-skip_chars" class="anchor"></a><code><span class="keyword">val</span> skip_chars : (char <span>&#45;&gt;</span> bool) <span>&#45;&gt;</span> unit <a href="index.html#type-t">t</a></code></dt><dd><p>Skip 0 or more chars satisfying the predicate.</p></dd></dl><dl><dt class="spec value" id="val-skip_space"><a href="#val-skip_space" class="anchor"></a><code><span class="keyword">val</span> skip_space : unit <a href="index.html#type-t">t</a></code></dt><dd><p>Skip ' ' and '\t'.</p></dd></dl><dl><dt class="spec value" id="val-skip_white"><a href="#val-skip_white" class="anchor"></a><code><span class="keyword">val</span> skip_white : unit <a href="index.html#type-t">t</a></code></dt><dd><p>Skip ' ' and '\t' and '\n'.</p></dd></dl><dl><dt class="spec value" id="val-is_alpha"><a href="#val-is_alpha" class="anchor"></a><code><span class="keyword">val</span> is_alpha : char <span>&#45;&gt;</span> bool</code></dt><dd><p>Is the char a letter?</p></dd></dl><dl><dt class="spec value" id="val-is_num"><a href="#val-is_num" class="anchor"></a><code><span class="keyword">val</span> is_num : char <span>&#45;&gt;</span> bool</code></dt><dd><p>Is the char a digit?</p></dd></dl><dl><dt class="spec value" id="val-is_alpha_num"><a href="#val-is_alpha_num" class="anchor"></a><code><span class="keyword">val</span> is_alpha_num : char <span>&#45;&gt;</span> bool</code></dt><dd><p>Is the char a letter or a digit?</p></dd></dl><dl><dt class="spec value" id="val-is_space"><a href="#val-is_space" class="anchor"></a><code><span class="keyword">val</span> is_space : char <span>&#45;&gt;</span> bool</code></dt><dd><p>True on ' ' and '\t'.</p></dd></dl><dl><dt class="spec value" id="val-is_white"><a href="#val-is_white" class="anchor"></a><code><span class="keyword">val</span> is_white : char <span>&#45;&gt;</span> bool</code></dt><dd><p>True on ' ' and '\t' and '\n'.</p></dd></dl><dl><dt class="spec value" id="val-(&lt;|&gt;)"><a href="#val-(&lt;|&gt;)" class="anchor"></a><code><span class="keyword">val</span> (&lt;|&gt;) : <span class="type-var">'a</span> <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a></code></dt><dd><p><code>a &lt;|&gt; b</code> tries to parse <code>a</code>, and if <code>a</code> fails without consuming any input, backtracks and tries to parse <code>b</code>, otherwise it fails as <code>a</code>. See <a href="index.html#val-try_"><code>try_</code></a> to ensure <code>a</code> does not consume anything (but it is best to avoid wrapping large parsers with <a href="index.html#val-try_"><code>try_</code></a>).</p></dd></dl><dl><dt class="spec value" id="val-(&lt;?&gt;)"><a href="#val-(&lt;?&gt;)" class="anchor"></a><code><span class="keyword">val</span> (&lt;?&gt;) : <span class="type-var">'a</span> <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> string <span>&#45;&gt;</span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a></code></dt><dd><p><code>a &lt;?&gt; msg</code> behaves like <code>a</code>, but if <code>a</code> fails without consuming any input, it fails with <code>msg</code> instead. Useful as the last choice in a series of <code>&lt;|&gt;</code>: <code>a &lt;|&gt; b &lt;|&gt; c &lt;?&gt; &quot;expected a|b|c&quot;</code>.</p></dd></dl><dl><dt class="spec value" id="val-try_"><a href="#val-try_" class="anchor"></a><code><span class="keyword">val</span> try_ : <span class="type-var">'a</span> <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a></code></dt><dd><p><code>try_ p</code> tries to parse like <code>p</code>, but backtracks if <code>p</code> fails. Useful in combination with <code>&lt;|&gt;</code>.</p></dd></dl><dl><dt class="spec value" id="val-suspend"><a href="#val-suspend" class="anchor"></a><code><span class="keyword">val</span> suspend : (unit <span>&#45;&gt;</span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a>) <span>&#45;&gt;</span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a></code></dt><dd><p><code>suspend f</code> is the same as <code>f ()</code>, but evaluates <code>f ()</code> only when needed.</p></dd></dl><dl><dt class="spec value" id="val-string"><a href="#val-string" class="anchor"></a><code><span class="keyword">val</span> string : string <span>&#45;&gt;</span> string <a href="index.html#type-t">t</a></code></dt><dd><p><code>string s</code> parses exactly the string <code>s</code>, and nothing else.</p></dd></dl><dl><dt class="spec value" id="val-many"><a href="#val-many" class="anchor"></a><code><span class="keyword">val</span> many : <span class="type-var">'a</span> <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> <span class="type-var">'a</span> list <a href="index.html#type-t">t</a></code></dt><dd><p><code>many p</code> parses a list of <code>p</code>, eagerly (as long as possible).</p></dd></dl><dl><dt class="spec value" id="val-many1"><a href="#val-many1" class="anchor"></a><code><span class="keyword">val</span> many1 : <span class="type-var">'a</span> <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> <span class="type-var">'a</span> list <a href="index.html#type-t">t</a></code></dt><dd><p>Parse a non-empty list.</p></dd></dl><dl><dt class="spec value" id="val-skip"><a href="#val-skip" class="anchor"></a><code><span class="keyword">val</span> skip : <span class="type-var">_</span> <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> unit <a href="index.html#type-t">t</a></code></dt><dd><p><code>skip p</code> parses zero or more times <code>p</code> and ignores its result.</p></dd></dl><dl><dt class="spec value" id="val-sep"><a href="#val-sep" class="anchor"></a><code><span class="keyword">val</span> sep : by:<span class="type-var">_</span> <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> <span class="type-var">'a</span> list <a href="index.html#type-t">t</a></code></dt><dd><p><code>sep ~by p</code> parses a list of <code>p</code> separated by <code>by</code>.</p></dd></dl><dl><dt class="spec value" id="val-sep1"><a href="#val-sep1" class="anchor"></a><code><span class="keyword">val</span> sep1 : by:<span class="type-var">_</span> <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> <span class="type-var">'a</span> list <a href="index.html#type-t">t</a></code></dt><dd><p><code>sep1 ~by p</code> parses a non empty list of <code>p</code>, separated by <code>by</code>.</p></dd></dl><dl><dt class="spec value" id="val-fix"><a href="#val-fix" class="anchor"></a><code><span class="keyword">val</span> fix : (<span class="type-var">'a</span> <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a>) <span>&#45;&gt;</span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a></code></dt><dd><p>Fixpoint combinator.</p></dd></dl><dl><dt class="spec value" id="val-memo"><a href="#val-memo" class="anchor"></a><code><span class="keyword">val</span> memo : <span class="type-var">'a</span> <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a></code></dt><dd><p>Memoize the parser. <code>memo p</code> will behave like <code>p</code>, but when called in a state (read: position in input) it has already processed, <code>memo p</code> returns a result directly. The implementation uses an underlying hashtable. This can be costly in memory, but improve the run time a lot if there is a lot of backtracking involving <code>p</code>.</p><p>This function is not thread-safe.</p></dd></dl><dl><dt class="spec value" id="val-fix_memo"><a href="#val-fix_memo" class="anchor"></a><code><span class="keyword">val</span> fix_memo : (<span class="type-var">'a</span> <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a>) <span>&#45;&gt;</span> <span class="type-var">'a</span> <a href="index.html#type-t">t</a></code></dt><dd><p>Like <a href="index.html#val-fix"><code>fix</code></a>, but the fixpoint is memoized.</p></dd></dl><dl><dt class="spec value" id="val-get_lnum"><a href="#val-get_lnum" class="anchor"></a><code><span class="keyword">val</span> get_lnum : int <a href="index.html#type-t">t</a></code></dt><dd><p>Reflect the current line number.</p></dd></dl><dl><dt class="spec value" id="val-get_cnum"><a href="#val-get_cnum" class="anchor"></a><code><span class="keyword">val</span> get_cnum : int <a href="index.html#type-t">t</a></code></dt><dd><p>Reflect the current column number.</p></dd></dl><dl><dt class="spec value" id="val-get_pos"><a href="#val-get_pos" class="anchor"></a><code><span class="keyword">val</span> get_pos : (int * int) <a href="index.html#type-t">t</a></code></dt><dd><p>Reflect the current (line, column) numbers.</p></dd></dl></section><section><header><h3 id="parse"><a href="#parse" class="anchor"></a>Parse</h3><p>Those functions have a label <code>~p</code> on the parser, since 0.14.</p></header><dl><dt class="spec value" id="val-parse"><a href="#val-parse" class="anchor"></a><code><span class="keyword">val</span> parse : <span class="type-var">'a</span> <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> <a href="index.html#type-state">state</a> <span>&#45;&gt;</span> <span class="type-var">'a</span> <a href="index.html#type-or_error">or_error</a></code></dt><dd><p><code>parse p st</code> applies <code>p</code> on the input, and returns <code>Ok x</code> if <code>p</code> succeeds with <code>x</code>, or <code>Error s</code> otherwise.</p></dd></dl><dl><dt class="spec value" id="val-parse_exn"><a href="#val-parse_exn" class="anchor"></a><code><span class="keyword">val</span> parse_exn : <span class="type-var">'a</span> <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> <a href="index.html#type-state">state</a> <span>&#45;&gt;</span> <span class="type-var">'a</span></code></dt><dd><p>Unsafe version of <a href="index.html#parse"><span>Parse</span></a>.</p><dl><dt>raises ParseError</dt><dd><p>if it fails.</p></dd></dl></dd></dl><dl><dt class="spec value" id="val-parse_string"><a href="#val-parse_string" class="anchor"></a><code><span class="keyword">val</span> parse_string : <span class="type-var">'a</span> <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> string <span>&#45;&gt;</span> <span class="type-var">'a</span> <a href="index.html#type-or_error">or_error</a></code></dt><dd><p>Specialization of <a href="index.html#parse"><span>Parse</span></a> for string inputs.</p></dd></dl><dl><dt class="spec value" id="val-parse_string_exn"><a href="#val-parse_string_exn" class="anchor"></a><code><span class="keyword">val</span> parse_string_exn : <span class="type-var">'a</span> <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> string <span>&#45;&gt;</span> <span class="type-var">'a</span></code></dt><dd><dl><dt>raises ParseError</dt><dd><p>if it fails.</p></dd></dl></dd></dl><dl><dt class="spec value" id="val-parse_file"><a href="#val-parse_file" class="anchor"></a><code><span class="keyword">val</span> parse_file : <span class="type-var">'a</span> <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> string <span>&#45;&gt;</span> <span class="type-var">'a</span> <a href="index.html#type-or_error">or_error</a></code></dt><dd><p><code>parse_file p file</code> parses <code>file</code> with <code>p</code> by opening the file and reading it whole.</p></dd></dl><dl><dt class="spec value" id="val-parse_file_exn"><a href="#val-parse_file_exn" class="anchor"></a><code><span class="keyword">val</span> parse_file_exn : <span class="type-var">'a</span> <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> string <span>&#45;&gt;</span> <span class="type-var">'a</span></code></dt><dd><dl><dt>raises ParseError</dt><dd><p>if it fails.</p></dd></dl></dd></dl></section><section><header><h3 id="infix"><a href="#infix" class="anchor"></a>Infix</h3></header><div class="spec module" id="module-Infix"><a href="#module-Infix" class="anchor"></a><code><span class="keyword">module</span> <a href="Infix/index.html">Infix</a> : <span class="keyword">sig</span> ... <span class="keyword">end</span></code></div></section><section><header><h3 id="utils"><a href="#utils" class="anchor"></a>Utils</h3><p>This is useful to parse OCaml-like values in a simple way.</p></header><div class="spec module" id="module-U"><a href="#module-U" class="anchor"></a><code><span class="keyword">module</span> <a href="U/index.html">U</a> : <span class="keyword">sig</span> ... <span class="keyword">end</span></code></div><div><div class="spec include"><div class="doc"><p>Let operators on OCaml &gt;= 4.08.0, nothing otherwise</p><dl><dt>since</dt><dd>2.8</dd></dl><details open="open"><summary><span class="def"><code><span class="keyword">include</span> <a href="../CCShimsMkLet_/index.html#module-type-S">CCShimsMkLet_.S</a> <span class="keyword">with</span> <span class="keyword">type</span> 'a <a href="../CCShimsMkLet_/module-type-S/index.html#type-t_let">t_let</a> := <span class="type-var">'a</span> <a href="index.html#type-t">t</a></code></span></summary><dl><dt class="spec type" id="type-t_let"><a href="#type-t_let" class="anchor"></a><code><span class="keyword">type</span> 'a t_let</code></dt></dl><dl><dt class="spec value" id="val-let+"><a href="#val-let+" class="anchor"></a><code><span class="keyword">val</span> let+ : <span class="type-var">'a</span> <a href="index.html#type-t_let">t_let</a> <span>&#45;&gt;</span> (<span class="type-var">'a</span> <span>&#45;&gt;</span> <span class="type-var">'b</span>) <span>&#45;&gt;</span> <span class="type-var">'b</span> <a href="index.html#type-t_let">t_let</a></code></dt><dt class="spec value" id="val-and+"><a href="#val-and+" class="anchor"></a><code><span class="keyword">val</span> and+ : <span class="type-var">'a</span> <a href="index.html#type-t_let">t_let</a> <span>&#45;&gt;</span> <span class="type-var">'b</span> <a href="index.html#type-t_let">t_let</a> <span>&#45;&gt;</span> (<span class="type-var">'a</span> * <span class="type-var">'b</span>) <a href="index.html#type-t_let">t_let</a></code></dt><dt class="spec value" id="val-let*"><a href="#val-let*" class="anchor"></a><code><span class="keyword">val</span> let* : <span class="type-var">'a</span> <a href="index.html#type-t_let">t_let</a> <span>&#45;&gt;</span> (<span class="type-var">'a</span> <span>&#45;&gt;</span> <span class="type-var">'b</span> <a href="index.html#type-t_let">t_let</a>) <span>&#45;&gt;</span> <span class="type-var">'b</span> <a href="index.html#type-t_let">t_let</a></code></dt><dt class="spec value" id="val-and*"><a href="#val-and*" class="anchor"></a><code><span class="keyword">val</span> and* : <span class="type-var">'a</span> <a href="index.html#type-t_let">t_let</a> <span>&#45;&gt;</span> <span class="type-var">'b</span> <a href="index.html#type-t_let">t_let</a> <span>&#45;&gt;</span> (<span class="type-var">'a</span> * <span class="type-var">'b</span>) <a href="index.html#type-t_let">t_let</a></code></dt></dl></details></div></div></div></section></div></body></html>