Version: 0.3.1

Parser

recurse

Recurse on a parser. Used in combination with {@see recursive()}. After calling this method, this parser behaves like a regular parser.

public function recurse(Parser $parser) : Parser

run

Run the parser on an input

public function run(string $input) : ParseResult

optional

Optionally parse something, but still succeed if the thing is not there.

public function optional() : Parser

or

Try the first parser, and failing that, try the second parser. Returns the first succeeding result, or the first failing result.

Caveat: The order matters! string('http')->or(string('https')

public function or(Parser $other) : Parser

followedBy

Alias for sequence(). Parse something, then follow by something else. Ignore the result of the first parser and return the result of the second parser.

public function followedBy(Parser $second) : Parser

sequence

Parse something, then follow by something else. Ignore the result of the first parser and return the result of the second parser.

public function sequence(Parser $second) : Parser

label

Label a parser. When a parser fails, instead of a generated error message, you'll see your label. eg (char(':')->followedBy(char(')')).followedBy(char(')')).

public function label(string $label) : Parser

bind

Create a parser that takes the output from the first parser (if successful) and feeds it to the callable. The callable must return another parser. If the first parser fails, the first parser is returned.

public function bind(callable $f) : Parser

map

Map a function over the parser (which in turn maps it over the result).

public function map(callable $transform) : Parser

continueFrom

Take the remaining input from the result and parse it

public function continueFrom(ParseResult $result) : ParseResult

construct

Construct a class with thee parser's output as the constructor argument

public function construct(string $className) : Parser

append

Combine the parser with another parser of the same type, which will cause the results to be appended.

public function append(Parser $other) : Parser

try

Try to parse the input, or throw an exception;

public function try(string $input) : ParseResult

apply

Sequential application.

The first parser must be of type Parser<callable(T2):T3>.

apply :: f (a -> b) -> f a -> f b

public function apply(Parser $parser) : Parser

thenIgnore

Sequence two parsers, and return the output of the first one, ignore the second.

public function thenIgnore(Parser $other) : Parser

notFollowedBy

notFollowedBy only succeeds when $second fails. It never consumes any input.

Example:

string("print") will also match "printXYZ"

string("print")->notFollowedBy(alphaNumChar())) will match "print something" but not "printXYZ something"

public function notFollowedBy(Parser $second) : Parser