Methods summary
abstract protected
boolean
|
#
atEnd( mixed $input )
Whether the given input sequence is empty.
Whether the given input sequence is empty.
Parameters
- $input
- The input sequence.
Returns
boolean True if empty, false otherwise.
|
abstract protected
mixed
|
#
head( mixed $input )
Get the first element of the given input sequence.
Get the first element of the given input sequence.
Parameters
- $input
- The input sequence
Returns
mixed The first element of the input sequence.
|
abstract protected
array
|
#
tail( mixed $input, array $pos )
Remove the first element of the given input sequence and advance the
position counter.
Remove the first element of the given input sequence and advance the
position counter.
Parameters
- $input
- The input sequence.
- $pos
Current position as a 2-element array consisting of a line
number and a column number. See Parco\Positional .
Returns
array A two-element array consisting of the remaining input
sequence and the position of the first element in the remaining
input sequence. If the remaining input sequence is empty, the
position returned should be array(-1, -1) . See
Parco\Positional .
|
abstract protected
string
|
#
show( mixed $element )
Convert an input sequence element to a string for use in failure
messages.
Convert an input sequence element to a string for use in failure
messages.
Parameters
- $element
- An input sequence element.
Returns
string String representation of element.
|
public
Parco\Parser
|
#
__get( string $name )
Lazily fetch a parser.
Parameters
- $name
- Name of parser method. Method must have zero parameters.
Returns
|
public
Parco\Parser
|
#
elem( mixed $e, boolean $strict = true )
A parser that accepts only the given element.
A parser that accepts only the given element.
elem($e) is a parser that succeeds if the first element in the input
is equal to $e .
Parameters
- $e
- An element.
- $strict
- If true,
=== will be used for comparison instead of == .
Returns
|
public
Parco\Parser
|
#
acceptIf( callable $predicate, callable|null $failure = null )
A parser that accepts input using a predicate.
A parser that accepts input using a predicate.
acceptIf($f) is a parser that succeeds if $f($x) = true , where $x
is the first element in the input. The second parameter is optional and
can be used to customize the failure message.
Parameters
- $predicate
- A predicate function.
- $failure
- A function that converts a failing input to a failure message.
Returns
|
public
Parco\Parser
|
#
phrase( Parco\Parser $p )
A parser that parses the entire input.
A parser that parses the entire input.
phrase($p) is a parser that succeeds if $p succeeds and no input
remains.
Parameters
Returns
|
public
Parco\Parser
|
#
positioned( Parco\Parser $p )
Add position to result of parser.
Add position to result of parser.
positioned($p) adds the position of the first input to the result of
$p . The result must implement Parco\Positional .
Parameters
Returns
|
public
Parco\Parser
|
#
opt( Parco\Parser $p )
Optional parser.
opt($p) is a parser that always succeeds and returns $x if $p
returns $x and null if $p fails.
Parameters
Returns
|
public
Parco\Parser
|
#
not( Parco\Parser $p )
Negating parser.
not($p) is a parser that fails if $p succeeds and succeeds if $p
fails. It never consumes any input.
Parameters
Returns
|
public
Parco\Parser
|
#
rep( Parco\Parser $p )
Repetition parser.
rep($p) is a parser that repeatedly uses $p to parse the input until
$p fails. The result is an array of all results.
Parameters
Returns
|
public
Parco\Parser
|
#
repsep( Parco\Parser $p, Parco\Parser $sep )
Interleaved repetition parser.
Interleaved repetition parser.
repsep($p, $sep) is a parser that repeatedly uses $p interleaved with
$sep to parse the input until $p fails. The result is an array of all
results of $p .
Parameters
- $p
- A parser.
- $sep
A parser that parses the elements that separate the elements
parsed by $p .
Returns
|
public
Parco\Parser
|
#
rep1( Parco\Parser $p )
Non-empty repetition parser.
Non-empty repetition parser.
rep1($p) is a parser that repeatedly uses $p to parse the input until
$p fails. It fails if the first use of $p fails. The result is an
array of all results.
Parameters
Returns
|
public
Parco\Parser
|
#
rep1sep( Parco\Parser $p, Parco\Parser $sep )
Non-empty interleaved repetition parser.
Non-empty interleaved repetition parser.
repsep($p, $sep) is a parser that repeatedly uses $p interleaved with
$sep to parse the input until $p fails. It fails if the first use of
$p fails. The result is an array of all results of $p .
Parameters
- $p
- A parser.
- $sep
A parser that parses the elements that separate the elements
parsed by $p .
Returns
|
public
Parco\Parser
|
#
repN( integer $num, Parco\Parser $p )
N-repetitions parser.
repN($n, $p) is a parser that uses $p to parse the input exactly $n
times. It fails if any of the uses of $p fails. The result is an array
of all results.
Parameters
- $num
- Number of repetitions.
- $p
- A parser.
Returns
|
public
Parco\Parser
|
#
seq( Parco\Parser $p, Parco\Parser $q )
Sequential composition of two or more parsers.
Sequential composition of two or more parsers.
seq($p, $q) is a parser that uses $p on the input followed by $q
on the remaining input. The parser fails if either $p or $q fails. The
result is an array of all results.
Additional parameters are accepted such that:
seq($p, $q, $r) = seq($p, seq($q, $r)) .
Parameters
- $p
- First parser.
- $q
- Second parser.
Returns
|
public
Parco\Parser
|
#
alt( Parco\Parser $p, Parco\Parser $q )
Alternative composition of two or more parsers.
Alternative composition of two or more parsers.
alt($p, $q) is a parser that uses $p on the input and if $p fails
uses $q on the same input. The parser fails if both $p or $q fail. The
result is the result of the first parser that succeeded.
An arbitrary number of additional parameters are accepted such that:
alt($p, $q, $r) = alt($p, alt($q, $r)) .
Parameters
- $p
- First parser.
- $q
- Second parser.
Returns
Parco\Parser An alternative composition of the input parsers.
|
public
Parco\Parser
|
#
success( mixed $result )
A parser that always succeeds.
A parser that always succeeds.
Parameters
Returns
|
public
Parco\Parser
|
#
failure( string $message )
A parser that always fails.
A parser that always fails.
Parameters
- $message
- Failure message.
Returns
|
public
|
#
chainl( Parco\Parser $p, Parco\Parser $sep )
A parser for left-associative chaining.
A parser for left-associative chaining.
Parameters
- $p
- A parser.
- $sep
A parser that parses the elements that separate the elements
parsed by $p and returns a left-associative function that
combines two elements returned by $p .
|
public
|
#
chainr( Parco\Parser $p, Parco\Parser $sep )
A parser for right-associative chaining.
A parser for right-associative chaining.
Parameters
- $p
- A parser.
- $sep
A parser that parses the elements that separate the elements
parsed by $p and returns a right-associative function that
combines two elements returned by $p .
|