mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-06 03:05:28 -05:00
372 lines
No EOL
25 KiB
HTML
372 lines
No EOL
25 KiB
HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
|
<html>
|
|
<head>
|
|
<link rel="stylesheet" href="style.css" type="text/css">
|
|
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
<link rel="Start" href="index.html">
|
|
<link rel="previous" href="Containers.Pair.html">
|
|
<link rel="next" href="Containers.Random.html">
|
|
<link rel="Up" href="Containers.html">
|
|
<link title="Index of types" rel=Appendix href="index_types.html">
|
|
<link title="Index of exceptions" rel=Appendix href="index_exceptions.html">
|
|
<link title="Index of values" rel=Appendix href="index_values.html">
|
|
<link title="Index of class methods" rel=Appendix href="index_methods.html">
|
|
<link title="Index of class types" rel=Appendix href="index_class_types.html">
|
|
<link title="Index of modules" rel=Appendix href="index_modules.html">
|
|
<link title="Index of module types" rel=Appendix href="index_module_types.html">
|
|
<link title="CCVector" rel="Chapter" href="CCVector.html">
|
|
<link title="CCHeap" rel="Chapter" href="CCHeap.html">
|
|
<link title="CCList" rel="Chapter" href="CCList.html">
|
|
<link title="CCOpt" rel="Chapter" href="CCOpt.html">
|
|
<link title="CCPair" rel="Chapter" href="CCPair.html">
|
|
<link title="CCFun" rel="Chapter" href="CCFun.html">
|
|
<link title="CCHash" rel="Chapter" href="CCHash.html">
|
|
<link title="CCInt" rel="Chapter" href="CCInt.html">
|
|
<link title="CCBool" rel="Chapter" href="CCBool.html">
|
|
<link title="CCFloat" rel="Chapter" href="CCFloat.html">
|
|
<link title="CCArray" rel="Chapter" href="CCArray.html">
|
|
<link title="CCRef" rel="Chapter" href="CCRef.html">
|
|
<link title="CCSet" rel="Chapter" href="CCSet.html">
|
|
<link title="CCOrd" rel="Chapter" href="CCOrd.html">
|
|
<link title="CCRandom" rel="Chapter" href="CCRandom.html">
|
|
<link title="CCString" rel="Chapter" href="CCString.html">
|
|
<link title="CCHashtbl" rel="Chapter" href="CCHashtbl.html">
|
|
<link title="CCMap" rel="Chapter" href="CCMap.html">
|
|
<link title="CCFormat" rel="Chapter" href="CCFormat.html">
|
|
<link title="CCIO" rel="Chapter" href="CCIO.html">
|
|
<link title="CCInt64" rel="Chapter" href="CCInt64.html">
|
|
<link title="CCChar" rel="Chapter" href="CCChar.html">
|
|
<link title="CCResult" rel="Chapter" href="CCResult.html">
|
|
<link title="CCParse" rel="Chapter" href="CCParse.html">
|
|
<link title="CCArray_slice" rel="Chapter" href="CCArray_slice.html">
|
|
<link title="CCListLabels" rel="Chapter" href="CCListLabels.html">
|
|
<link title="CCArrayLabels" rel="Chapter" href="CCArrayLabels.html">
|
|
<link title="CCEqual" rel="Chapter" href="CCEqual.html">
|
|
<link title="Containers" rel="Chapter" href="Containers.html">
|
|
<link title="CCKTree" rel="Chapter" href="CCKTree.html">
|
|
<link title="CCKList" rel="Chapter" href="CCKList.html">
|
|
<link title="CCLazy_list" rel="Chapter" href="CCLazy_list.html">
|
|
<link title="CCMultiMap" rel="Chapter" href="CCMultiMap.html">
|
|
<link title="CCMultiSet" rel="Chapter" href="CCMultiSet.html">
|
|
<link title="CCTrie" rel="Chapter" href="CCTrie.html">
|
|
<link title="CCFlatHashtbl" rel="Chapter" href="CCFlatHashtbl.html">
|
|
<link title="CCCache" rel="Chapter" href="CCCache.html">
|
|
<link title="CCPersistentHashtbl" rel="Chapter" href="CCPersistentHashtbl.html">
|
|
<link title="CCDeque" rel="Chapter" href="CCDeque.html">
|
|
<link title="CCFQueue" rel="Chapter" href="CCFQueue.html">
|
|
<link title="CCBV" rel="Chapter" href="CCBV.html">
|
|
<link title="CCMixtbl" rel="Chapter" href="CCMixtbl.html">
|
|
<link title="CCMixmap" rel="Chapter" href="CCMixmap.html">
|
|
<link title="CCRingBuffer" rel="Chapter" href="CCRingBuffer.html">
|
|
<link title="CCIntMap" rel="Chapter" href="CCIntMap.html">
|
|
<link title="CCPersistentArray" rel="Chapter" href="CCPersistentArray.html">
|
|
<link title="CCMixset" rel="Chapter" href="CCMixset.html">
|
|
<link title="CCGraph" rel="Chapter" href="CCGraph.html">
|
|
<link title="CCHashSet" rel="Chapter" href="CCHashSet.html">
|
|
<link title="CCBitField" rel="Chapter" href="CCBitField.html">
|
|
<link title="CCHashTrie" rel="Chapter" href="CCHashTrie.html">
|
|
<link title="CCWBTree" rel="Chapter" href="CCWBTree.html">
|
|
<link title="CCRAL" rel="Chapter" href="CCRAL.html">
|
|
<link title="CCSimple_queue" rel="Chapter" href="CCSimple_queue.html">
|
|
<link title="CCImmutArray" rel="Chapter" href="CCImmutArray.html">
|
|
<link title="CCHet" rel="Chapter" href="CCHet.html">
|
|
<link title="CCZipper" rel="Chapter" href="CCZipper.html">
|
|
<link title="CCPool" rel="Chapter" href="CCPool.html">
|
|
<link title="CCLock" rel="Chapter" href="CCLock.html">
|
|
<link title="CCSemaphore" rel="Chapter" href="CCSemaphore.html">
|
|
<link title="CCThread" rel="Chapter" href="CCThread.html">
|
|
<link title="CCBlockingQueue" rel="Chapter" href="CCBlockingQueue.html">
|
|
<link title="CCTimer" rel="Chapter" href="CCTimer.html">
|
|
<link title="CCUnix" rel="Chapter" href="CCUnix.html">
|
|
<link title="CCSexp" rel="Chapter" href="CCSexp.html">
|
|
<link title="CCSexp_lex" rel="Chapter" href="CCSexp_lex.html"><link title="Input" rel="Section" href="#2_Input">
|
|
<link title="Combinators" rel="Section" href="#2_Combinators">
|
|
<link title="Parse" rel="Section" href="#2_Parse">
|
|
<link title="Infix" rel="Section" href="#2_Infix">
|
|
<link title="Utils" rel="Section" href="#2_Utils">
|
|
<title>Containers doc : Containers.Parse</title>
|
|
</head>
|
|
<body>
|
|
<div class="navbar"><a class="pre" href="Containers.Pair.html" title="Containers.Pair">Previous</a>
|
|
<a class="up" href="Containers.html" title="Containers">Up</a>
|
|
<a class="post" href="Containers.Random.html" title="Containers.Random">Next</a>
|
|
</div>
|
|
<h1>Module <a href="type_Containers.Parse.html">Containers.Parse</a></h1>
|
|
|
|
<pre><span class="keyword">module</span> Parse: <code class="type"><a href="CCParse.html">CCParse</a></code></pre><hr width="100%">
|
|
|
|
<pre><span id="TYPEor_error"><span class="keyword">type</span> <code class="type">'a</code> or_error</span> = <code class="type">('a, string) Result.result</code> </pre>
|
|
|
|
|
|
<pre><span id="TYPEline_num"><span class="keyword">type</span> <code class="type"></code>line_num</span> = <code class="type">int</code> </pre>
|
|
|
|
|
|
<pre><span id="TYPEcol_num"><span class="keyword">type</span> <code class="type"></code>col_num</span> = <code class="type">int</code> </pre>
|
|
|
|
|
|
<pre><span id="TYPEparse_branch"><span class="keyword">type</span> <code class="type"></code>parse_branch</span> </pre>
|
|
|
|
|
|
<pre><span id="VALstring_of_branch"><span class="keyword">val</span> string_of_branch</span> : <code class="type"><a href="CCParse.html#TYPEparse_branch">parse_branch</a> -> string</code></pre>
|
|
<pre><span id="EXCEPTIONParseError"><span class="keyword">exception</span> ParseError</span> <span class="keyword">of</span> <code class="type"><a href="CCParse.html#TYPEparse_branch">parse_branch</a> * (unit -> string)</code></pre>
|
|
<div class="info ">
|
|
parsing branch * message<br>
|
|
</div>
|
|
<br>
|
|
<h2 id="2_Input">Input</h2><br>
|
|
|
|
<pre><span id="TYPEposition"><span class="keyword">type</span> <code class="type"></code>position</span> </pre>
|
|
|
|
|
|
<pre><span id="TYPEstate"><span class="keyword">type</span> <code class="type"></code>state</span> </pre>
|
|
|
|
|
|
<pre><span id="VALstate_of_string"><span class="keyword">val</span> state_of_string</span> : <code class="type">string -> <a href="CCParse.html#TYPEstate">state</a></code></pre><br>
|
|
<h2 id="2_Combinators">Combinators</h2><br>
|
|
|
|
<pre><span id="TYPEt"><span class="keyword">type</span> <code class="type">'a</code> t</span> = <code class="type"><a href="CCParse.html#TYPEstate">state</a> -> ok:('a -> unit) -> err:(exn -> unit) -> unit</code> </pre>
|
|
<div class="info ">
|
|
Takes the input and two continuations:
|
|
<ul>
|
|
<li><code class="code">ok</code> to call with the result when it's done</li>
|
|
<li><code class="code">err</code> to call when the parser met an error</li>
|
|
</ul>
|
|
<br>
|
|
<b>Raises</b> <code>ParseError</code> in case of failure<br>
|
|
</div>
|
|
|
|
|
|
<pre><span id="VALreturn"><span class="keyword">val</span> return</span> : <code class="type">'a -> 'a <a href="CCParse.html#TYPEt">t</a></code></pre><div class="info ">
|
|
Always succeeds, without consuming its input<br>
|
|
</div>
|
|
|
|
<pre><span id="VALpure"><span class="keyword">val</span> pure</span> : <code class="type">'a -> 'a <a href="CCParse.html#TYPEt">t</a></code></pre><div class="info ">
|
|
Synonym to <a href="CCParse.html#VALreturn"><code class="code"><span class="constructor">CCParse</span>.return</code></a><br>
|
|
</div>
|
|
|
|
<pre><span id="VAL(>|=)"><span class="keyword">val</span> (>|=)</span> : <code class="type">'a <a href="CCParse.html#TYPEt">t</a> -> ('a -> 'b) -> 'b <a href="CCParse.html#TYPEt">t</a></code></pre><div class="info ">
|
|
Map<br>
|
|
</div>
|
|
|
|
<pre><span id="VALmap"><span class="keyword">val</span> map</span> : <code class="type">('a -> 'b) -> 'a <a href="CCParse.html#TYPEt">t</a> -> 'b <a href="CCParse.html#TYPEt">t</a></code></pre>
|
|
<pre><span id="VALmap2"><span class="keyword">val</span> map2</span> : <code class="type">('a -> 'b -> 'c) -> 'a <a href="CCParse.html#TYPEt">t</a> -> 'b <a href="CCParse.html#TYPEt">t</a> -> 'c <a href="CCParse.html#TYPEt">t</a></code></pre>
|
|
<pre><span id="VALmap3"><span class="keyword">val</span> map3</span> : <code class="type">('a -> 'b -> 'c -> 'd) -><br> 'a <a href="CCParse.html#TYPEt">t</a> -> 'b <a href="CCParse.html#TYPEt">t</a> -> 'c <a href="CCParse.html#TYPEt">t</a> -> 'd <a href="CCParse.html#TYPEt">t</a></code></pre>
|
|
<pre><span id="VAL(>>=)"><span class="keyword">val</span> (>>=)</span> : <code class="type">'a <a href="CCParse.html#TYPEt">t</a> -> ('a -> 'b <a href="CCParse.html#TYPEt">t</a>) -> 'b <a href="CCParse.html#TYPEt">t</a></code></pre><div class="info ">
|
|
Monadic bind<br>
|
|
</div>
|
|
|
|
<pre><span id="VAL(<*>)"><span class="keyword">val</span> (<*>)</span> : <code class="type">('a -> 'b) <a href="CCParse.html#TYPEt">t</a> -> 'a <a href="CCParse.html#TYPEt">t</a> -> 'b <a href="CCParse.html#TYPEt">t</a></code></pre><div class="info ">
|
|
Applicative<br>
|
|
</div>
|
|
|
|
<pre><span id="VAL( <* )"><span class="keyword">val</span> ( <* )</span> : <code class="type">'a <a href="CCParse.html#TYPEt">t</a> -> 'b <a href="CCParse.html#TYPEt">t</a> -> 'a <a href="CCParse.html#TYPEt">t</a></code></pre><div class="info ">
|
|
<code class="code">a <* b</code> parses <code class="code">a</code> into <code class="code">x</code>, parses <code class="code">b</code> and ignores its result,
|
|
and returns <code class="code">x</code><br>
|
|
</div>
|
|
|
|
<pre><span id="VAL( *> )"><span class="keyword">val</span> ( *> )</span> : <code class="type">'b <a href="CCParse.html#TYPEt">t</a> -> 'a <a href="CCParse.html#TYPEt">t</a> -> 'a <a href="CCParse.html#TYPEt">t</a></code></pre><div class="info ">
|
|
<code class="code">a *> b</code> parses <code class="code">a</code>, then parses <code class="code">b</code> into <code class="code">x</code>, and returns <code class="code">x</code>. The
|
|
results of <code class="code">a</code> is ignored.<br>
|
|
</div>
|
|
|
|
<pre><span id="VALfail"><span class="keyword">val</span> fail</span> : <code class="type">string -> 'a <a href="CCParse.html#TYPEt">t</a></code></pre><div class="info ">
|
|
<code class="code">fail msg</code> fails with the given message. It can trigger a backtrack<br>
|
|
</div>
|
|
|
|
<pre><span id="VALfailf"><span class="keyword">val</span> failf</span> : <code class="type">('a, unit, string, 'b <a href="CCParse.html#TYPEt">t</a>) Pervasives.format4 -> 'a</code></pre><div class="info ">
|
|
<code class="code"><span class="constructor">Format</span>.sprintf</code> version of <a href="CCParse.html#VALfail"><code class="code"><span class="constructor">CCParse</span>.fail</code></a><br>
|
|
</div>
|
|
|
|
<pre><span id="VALparsing"><span class="keyword">val</span> parsing</span> : <code class="type">string -> 'a <a href="CCParse.html#TYPEt">t</a> -> 'a <a href="CCParse.html#TYPEt">t</a></code></pre><div class="info ">
|
|
<code class="code">parsing s p</code> behaves the same as <code class="code">p</code>, with the information that
|
|
we are parsing <code class="code">s</code>, if <code class="code">p</code> fails<br>
|
|
</div>
|
|
|
|
<pre><span id="VALeoi"><span class="keyword">val</span> eoi</span> : <code class="type">unit <a href="CCParse.html#TYPEt">t</a></code></pre><div class="info ">
|
|
Expect the end of input, fails otherwise<br>
|
|
</div>
|
|
|
|
<pre><span id="VALnop"><span class="keyword">val</span> nop</span> : <code class="type">unit <a href="CCParse.html#TYPEt">t</a></code></pre><div class="info ">
|
|
Succeed with <code class="code">()</code><br>
|
|
</div>
|
|
|
|
<pre><span id="VALchar"><span class="keyword">val</span> char</span> : <code class="type">char -> char <a href="CCParse.html#TYPEt">t</a></code></pre><div class="info ">
|
|
<code class="code">char c</code> parses the char <code class="code">c</code> and nothing else<br>
|
|
</div>
|
|
|
|
<pre><span id="VALchar_if"><span class="keyword">val</span> char_if</span> : <code class="type">(char -> bool) -> char <a href="CCParse.html#TYPEt">t</a></code></pre><div class="info ">
|
|
<code class="code">char_if f</code> parses a character <code class="code">c</code> if <code class="code">f c = <span class="keyword">true</span></code><br>
|
|
</div>
|
|
|
|
<pre><span id="VALchars_if"><span class="keyword">val</span> chars_if</span> : <code class="type">(char -> bool) -> string <a href="CCParse.html#TYPEt">t</a></code></pre><div class="info ">
|
|
<code class="code">chars_if f</code> parses a string of chars that satisfy <code class="code">f</code><br>
|
|
</div>
|
|
|
|
<pre><span id="VALchars1_if"><span class="keyword">val</span> chars1_if</span> : <code class="type">(char -> bool) -> string <a href="CCParse.html#TYPEt">t</a></code></pre><div class="info ">
|
|
Same as <a href="CCParse.html#VALchars_if"><code class="code"><span class="constructor">CCParse</span>.chars_if</code></a>, but only non-empty strings<br>
|
|
</div>
|
|
|
|
<pre><span id="VALendline"><span class="keyword">val</span> endline</span> : <code class="type">char <a href="CCParse.html#TYPEt">t</a></code></pre><div class="info ">
|
|
Parses '\n'<br>
|
|
</div>
|
|
|
|
<pre><span id="VALspace"><span class="keyword">val</span> space</span> : <code class="type">char <a href="CCParse.html#TYPEt">t</a></code></pre><div class="info ">
|
|
Tab or space<br>
|
|
</div>
|
|
|
|
<pre><span id="VALwhite"><span class="keyword">val</span> white</span> : <code class="type">char <a href="CCParse.html#TYPEt">t</a></code></pre><div class="info ">
|
|
Tab or space or newline<br>
|
|
</div>
|
|
|
|
<pre><span id="VALskip_chars"><span class="keyword">val</span> skip_chars</span> : <code class="type">(char -> bool) -> unit <a href="CCParse.html#TYPEt">t</a></code></pre><div class="info ">
|
|
Skip 0 or more chars satisfying the predicate<br>
|
|
</div>
|
|
|
|
<pre><span id="VALskip_space"><span class="keyword">val</span> skip_space</span> : <code class="type">unit <a href="CCParse.html#TYPEt">t</a></code></pre><div class="info ">
|
|
Skip ' ' and '\t'<br>
|
|
</div>
|
|
|
|
<pre><span id="VALskip_white"><span class="keyword">val</span> skip_white</span> : <code class="type">unit <a href="CCParse.html#TYPEt">t</a></code></pre><div class="info ">
|
|
Skip ' ' and '\t' and '\n'<br>
|
|
</div>
|
|
|
|
<pre><span id="VALis_alpha"><span class="keyword">val</span> is_alpha</span> : <code class="type">char -> bool</code></pre><div class="info ">
|
|
Is the char a letter?<br>
|
|
</div>
|
|
|
|
<pre><span id="VALis_num"><span class="keyword">val</span> is_num</span> : <code class="type">char -> bool</code></pre><div class="info ">
|
|
Is the char a digit?<br>
|
|
</div>
|
|
|
|
<pre><span id="VALis_alpha_num"><span class="keyword">val</span> is_alpha_num</span> : <code class="type">char -> bool</code></pre>
|
|
<pre><span id="VALis_space"><span class="keyword">val</span> is_space</span> : <code class="type">char -> bool</code></pre><div class="info ">
|
|
True on ' ' and '\t'<br>
|
|
</div>
|
|
|
|
<pre><span id="VALis_white"><span class="keyword">val</span> is_white</span> : <code class="type">char -> bool</code></pre><div class="info ">
|
|
True on ' ' and '\t' and '\n'<br>
|
|
</div>
|
|
|
|
<pre><span id="VAL(<|>)"><span class="keyword">val</span> (<|>)</span> : <code class="type">'a <a href="CCParse.html#TYPEt">t</a> -> 'a <a href="CCParse.html#TYPEt">t</a> -> 'a <a href="CCParse.html#TYPEt">t</a></code></pre><div class="info ">
|
|
<code class="code">a <|> b</code> tries to parse <code class="code">a</code>, and if <code class="code">a</code> fails without
|
|
consuming any input, backtracks and tries
|
|
to parse <code class="code">b</code>, otherwise it fails as <code class="code">a</code>.
|
|
See <a href="CCParse.html#VALtry_"><code class="code"><span class="constructor">CCParse</span>.try_</code></a> to ensure <code class="code">a</code> does not consume anything (but it is best
|
|
to avoid wrapping large parsers with <a href="CCParse.html#VALtry_"><code class="code"><span class="constructor">CCParse</span>.try_</code></a>)<br>
|
|
</div>
|
|
|
|
<pre><span id="VAL(<?>)"><span class="keyword">val</span> (<?>)</span> : <code class="type">'a <a href="CCParse.html#TYPEt">t</a> -> string -> 'a <a href="CCParse.html#TYPEt">t</a></code></pre><div class="info ">
|
|
<code class="code">a <?> msg</code> behaves like <code class="code">a</code>, but if <code class="code">a</code> fails without
|
|
consuming any input, it fails with <code class="code">msg</code>
|
|
instead. Useful as the last choice in a series of <code class="code"><|></code>:
|
|
<code class="code">a <|> b <|> c <?> <span class="string">"expected a|b|c"</span></code><br>
|
|
</div>
|
|
|
|
<pre><span id="VALtry_"><span class="keyword">val</span> try_</span> : <code class="type">'a <a href="CCParse.html#TYPEt">t</a> -> 'a <a href="CCParse.html#TYPEt">t</a></code></pre><div class="info ">
|
|
<code class="code">try_ p</code> tries to parse like <code class="code">p</code>, but backtracks if <code class="code">p</code> fails.
|
|
Useful in combination with <code class="code"><|></code><br>
|
|
</div>
|
|
|
|
<pre><span id="VALsuspend"><span class="keyword">val</span> suspend</span> : <code class="type">(unit -> 'a <a href="CCParse.html#TYPEt">t</a>) -> 'a <a href="CCParse.html#TYPEt">t</a></code></pre><div class="info ">
|
|
<code class="code">suspend f</code> is the same as <code class="code">f ()</code>, but evaluates <code class="code">f ()</code> only
|
|
when needed<br>
|
|
</div>
|
|
|
|
<pre><span id="VALstring"><span class="keyword">val</span> string</span> : <code class="type">string -> string <a href="CCParse.html#TYPEt">t</a></code></pre><div class="info ">
|
|
<code class="code">string s</code> parses exactly the string <code class="code">s</code>, and nothing else<br>
|
|
</div>
|
|
|
|
<pre><span id="VALmany"><span class="keyword">val</span> many</span> : <code class="type">'a <a href="CCParse.html#TYPEt">t</a> -> 'a list <a href="CCParse.html#TYPEt">t</a></code></pre><div class="info ">
|
|
<code class="code">many p</code> parses a list of <code class="code">p</code>, eagerly (as long as possible)<br>
|
|
</div>
|
|
|
|
<pre><span id="VALmany1"><span class="keyword">val</span> many1</span> : <code class="type">'a <a href="CCParse.html#TYPEt">t</a> -> 'a list <a href="CCParse.html#TYPEt">t</a></code></pre><div class="info ">
|
|
parses a non empty list<br>
|
|
</div>
|
|
|
|
<pre><span id="VALskip"><span class="keyword">val</span> skip</span> : <code class="type">'a <a href="CCParse.html#TYPEt">t</a> -> unit <a href="CCParse.html#TYPEt">t</a></code></pre><div class="info ">
|
|
<code class="code">skip p</code> parses zero or more times <code class="code">p</code> and ignores its result<br>
|
|
</div>
|
|
|
|
<pre><span id="VALsep"><span class="keyword">val</span> sep</span> : <code class="type">by:'b <a href="CCParse.html#TYPEt">t</a> -> 'a <a href="CCParse.html#TYPEt">t</a> -> 'a list <a href="CCParse.html#TYPEt">t</a></code></pre><div class="info ">
|
|
<code class="code">sep ~by p</code> parses a list of <code class="code">p</code> separated by <code class="code">by</code><br>
|
|
</div>
|
|
|
|
<pre><span id="VALsep1"><span class="keyword">val</span> sep1</span> : <code class="type">by:'b <a href="CCParse.html#TYPEt">t</a> -> 'a <a href="CCParse.html#TYPEt">t</a> -> 'a list <a href="CCParse.html#TYPEt">t</a></code></pre><div class="info ">
|
|
<code class="code">sep1 ~by p</code> parses a non empty list of <code class="code">p</code>, separated by <code class="code">by</code><br>
|
|
</div>
|
|
|
|
<pre><span id="VALfix"><span class="keyword">val</span> fix</span> : <code class="type">('a <a href="CCParse.html#TYPEt">t</a> -> 'a <a href="CCParse.html#TYPEt">t</a>) -> 'a <a href="CCParse.html#TYPEt">t</a></code></pre><div class="info ">
|
|
Fixpoint combinator<br>
|
|
</div>
|
|
|
|
<pre><span id="VALmemo"><span class="keyword">val</span> memo</span> : <code class="type">'a <a href="CCParse.html#TYPEt">t</a> -> 'a <a href="CCParse.html#TYPEt">t</a></code></pre><div class="info ">
|
|
Memoize the parser. <code class="code">memo p</code> will behave like <code class="code">p</code>, but when called
|
|
in a state (read: position in input) it has already processed, <code class="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 class="code">p</code>.
|
|
<p>
|
|
|
|
This function is not thread-safe.<br>
|
|
</div>
|
|
|
|
<pre><span id="VALfix_memo"><span class="keyword">val</span> fix_memo</span> : <code class="type">('a <a href="CCParse.html#TYPEt">t</a> -> 'a <a href="CCParse.html#TYPEt">t</a>) -> 'a <a href="CCParse.html#TYPEt">t</a></code></pre><div class="info ">
|
|
Same as <a href="CCParse.html#VALfix"><code class="code"><span class="constructor">CCParse</span>.fix</code></a>, but the fixpoint is memoized.<br>
|
|
</div>
|
|
|
|
<pre><span id="VALget_lnum"><span class="keyword">val</span> get_lnum</span> : <code class="type">int <a href="CCParse.html#TYPEt">t</a></code></pre><div class="info ">
|
|
Reflects the current line number<br>
|
|
</div>
|
|
|
|
<pre><span id="VALget_cnum"><span class="keyword">val</span> get_cnum</span> : <code class="type">int <a href="CCParse.html#TYPEt">t</a></code></pre><div class="info ">
|
|
Reflects the current column number<br>
|
|
</div>
|
|
|
|
<pre><span id="VALget_pos"><span class="keyword">val</span> get_pos</span> : <code class="type">(int * int) <a href="CCParse.html#TYPEt">t</a></code></pre><div class="info ">
|
|
Reflects the current (line, column) numbers<br>
|
|
</div>
|
|
<br>
|
|
<h2 id="2_Parse">Parse</h2>
|
|
<p>
|
|
|
|
Those functions have a label <code class="code">~p</code> on the parser, since 0.14.<br>
|
|
|
|
<pre><span id="VALparse"><span class="keyword">val</span> parse</span> : <code class="type">'a <a href="CCParse.html#TYPEt">t</a> -> <a href="CCParse.html#TYPEstate">state</a> -> 'a <a href="CCParse.html#TYPEor_error">or_error</a></code></pre><div class="info ">
|
|
<code class="code">parse p st</code> applies <code class="code">p</code> on the input, and returns <code class="code"><span class="constructor">Ok</span> x</code> if
|
|
<code class="code">p</code> succeeds with <code class="code">x</code>, or <code class="code"><span class="constructor">Error</span> s</code> otherwise<br>
|
|
</div>
|
|
|
|
<pre><span id="VALparse_exn"><span class="keyword">val</span> parse_exn</span> : <code class="type">'a <a href="CCParse.html#TYPEt">t</a> -> <a href="CCParse.html#TYPEstate">state</a> -> 'a</code></pre><div class="info ">
|
|
Unsafe version of <a href="CCParse.html#VALparse"><code class="code"><span class="constructor">CCParse</span>.parse</code></a><br>
|
|
<b>Raises</b> <code>ParseError</code> if it fails<br>
|
|
</div>
|
|
|
|
<pre><span id="VALparse_string"><span class="keyword">val</span> parse_string</span> : <code class="type">'a <a href="CCParse.html#TYPEt">t</a> -> string -> 'a <a href="CCParse.html#TYPEor_error">or_error</a></code></pre><div class="info ">
|
|
Specialization of <a href="CCParse.html#VALparse"><code class="code"><span class="constructor">CCParse</span>.parse</code></a> for string inputs<br>
|
|
</div>
|
|
|
|
<pre><span id="VALparse_string_exn"><span class="keyword">val</span> parse_string_exn</span> : <code class="type">'a <a href="CCParse.html#TYPEt">t</a> -> string -> 'a</code></pre><div class="info ">
|
|
<b>Raises</b> <code>ParseError</code> if it fails<br>
|
|
</div>
|
|
|
|
<pre><span id="VALparse_file"><span class="keyword">val</span> parse_file</span> : <code class="type">'a <a href="CCParse.html#TYPEt">t</a> -> string -> 'a <a href="CCParse.html#TYPEor_error">or_error</a></code></pre><div class="info ">
|
|
<code class="code">parse_file p file</code> parses <code class="code">file</code> with <code class="code">p</code> by opening the file
|
|
and reading it whole.<br>
|
|
</div>
|
|
|
|
<pre><span id="VALparse_file_exn"><span class="keyword">val</span> parse_file_exn</span> : <code class="type">'a <a href="CCParse.html#TYPEt">t</a> -> string -> 'a</code></pre><div class="info ">
|
|
<b>Raises</b> <code>ParseError</code> if it fails<br>
|
|
</div>
|
|
<br>
|
|
<h2 id="2_Infix">Infix</h2><br>
|
|
|
|
<pre><span class="keyword">module</span> <a href="CCParse.Infix.html">Infix</a>: <code class="code"><span class="keyword">sig</span></code> <a href="CCParse.Infix.html">..</a> <code class="code"><span class="keyword">end</span></code></pre><br>
|
|
<h2 id="2_Utils">Utils</h2>
|
|
<p>
|
|
|
|
This is useful to parse OCaml-like values in a simple way.<br>
|
|
|
|
<pre><span class="keyword">module</span> <a href="CCParse.U.html">U</a>: <code class="code"><span class="keyword">sig</span></code> <a href="CCParse.U.html">..</a> <code class="code"><span class="keyword">end</span></code></pre></body></html> |