Artifact Content

Artifact eabba6f014009cbc7494061c2380d64fd8e60303:

Wiki page [API Reference] by User 2016-11-21 12:55:39.
D 2016-11-21T12:55:39.195
L API\sReference
P 4bdf078f0d3f837e7fb560b3ee7d7e520775d2b3
U User
W 3276
<h1><i>PComb API</i></h1>

<div><i>This is meant to be a complete reference for all of the functions and
data types that comprise PComb. Being complete, they can not necessarily be in
order of how a programmer would use them. If the information that is presented
here is too confusing, consider looking at the
<a href="/user/acrossland/repository/pcomb/wiki?name=Getting+Started">Getting
Started</a> page. Also, the PComb repo has a full demo application in the <b>app/&nbsp;</b>subdirectory,
and that would be an excellent starting point for learning how to use the
library.</i></div>

<div><i><br>
</i></div>

<div><i><font color="#ff0000"><b>This document is incomplete. It is still being
written.</b></font></i></div>

<div><i><br>
</i></div>

<h2><i>Types</i></h2>

<h3><i>Parser</i></h3>
<pre><i><font face="Courier New">export type Parser = (input: ParserInput, output: ParserOutput, action?: ParserAction) =&gt; ParseResult;</font></i></pre>

<div><i>The Parser type is a function signature that should be implemented by
any function that wants to acts as a parser. All the standard parsers that are
supplied by the PComb library do so, but client code can also implement its own
special-purpose parsers by implementing this signature.</i></div>

<div><i><br>
</i></div>

<h3><i>ParseResult</i></h3>
<pre><i><font face="Courier New">export type ParseResult = <a href="/user/acrossland/repository/pcomb/wiki?name=boolean%2C+ParserInput%2C+ParserOutput">boolean, ParserInput, ParserOutput</a>;</font></i></pre>

<p><font face="Arial"><i>The <b>ParseResult </b>tuple is returned by all parser
functions. The first value indicates if the parser successfully matched its
input. If the value if <b>false, </b>the remaining parameters will be identical
to the objects that were supplied in the call to the <b>Parse</b>&nbsp;function.
If <b>true</b>&nbsp;is returned, the <b>ParserInput</b>&nbsp;returned will have
its <b>text</b>&nbsp;field set to have only the input data that was not
consumed by parsing, and the <b>ParserOutput</b>&nbsp;will have its <b>matched</b>&nbsp;list
set to contain all of the individual strings that were matched by each discrete
parsing step as well as any application-specific fields that were set by <b>ParserAction</b>&nbsp;functions.</i></font></p>

<h3><br>
</h3>

<h3>ParserOutput</h3>
<pre><font face="Courier New">export interface ParserOutput {<br>


&nbsp; &nbsp; /** The text that was matched by the parser. */<br>


&nbsp; &nbsp; matched: Array&lt;string&gt;;<br>


&nbsp; &nbsp; copy(): ParserOutput;<br>


}</font></pre>

<div><i>The ParserOutput interface must be implemented by a class that is
supplied by the client code. The object may implement any number of other
properties and methods, but any such custom values must be copied by the
implementation of the <b>copy</b>&nbsp;method.</i></div>

<div><i><br>
</i></div>

<h3><i>ParserInput</i></h3>

<div><i>
<pre><font face="Courier New">export interface ParserInput {<br>


&nbsp; &nbsp; /** What is the text that is being parsed? */<br>


&nbsp; &nbsp; text: string;<br>


&nbsp; &nbsp; copy(): ParserInput;<br>


}</font></pre>

<div>The <b>ParserInput</b>&nbsp;interface must be implemented by a class that
is supplied by the client code.</div></i></div>

Z 9187d41053e844bb1fa34a5997c797a0