Version: 0.4.0



Create a recursive parser. Used in combination with recurse(Parser).

public static function recursive() : Parser


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 the parser on an input

public function run(Stream $input) : ParseResult


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

public function optional() : Parser


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


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


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


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 a function over the parser (which in turn maps it over the result).

public function map(callable $transform) : Parser


Take the remaining input from the result and parse it.

public function continueFrom(ParseResult $result) : ParseResult


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

public function construct(string $className) : Parser


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 to parse a string. Alias of try(new StringStream($string)).

public function tryString(string $input) : ParseResult


Try to parse the input, or throw an exception.

public function try(Stream $input) : ParseResult


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


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

public function thenIgnore(Parser $other) : Parser


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


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

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

public function notFollowedBy(Parser $second) : Parser


Label a parser. When a parser fails, you'll see your label as the "expected" value. As a best practice, the labels should make sense to the person who provides the input for your parser. That's often an end user or a third party, so keep them in mind.

public function label(string $label) : Parser


If the parser is successful, call the $receiver function with the output of the parser. The resulting parser behaves identical to the original one. This combinator is useful for expressing side effects during the parsing process. It can be hooked into existing event publishing libraries by using $receiver as an adapter for those. Other use cases are logging, caching, performing an action whenever a value is matched in a long running input stream, ...

public function emit(callable $receiver) : Parser