Documentation

primitives.php

This file is part of the Parsica library.

Copyright (c) 2020 Mathias Verraes mathias@verraes.net

For the full copyright and license information, please view the LICENSE file that was distributed with this source code.

Table of Contents

Functions

satisfy()  : Parser
A parser that satisfies a predicate on a single token. Useful as a building block for writing things like char(), digit().
skipWhile()  : Parser
Skip 0 or more characters as long as the predicate holds.
skipWhile1()  : Parser
Skip 1 or more characters as long as the predicate holds.
takeWhile()  : Parser
Keep parsing 0 or more characters as long as the predicate holds.
takeWhile1()  : Parser
Keep parsing 1 or more characters as long as the predicate holds.
anySingle()  : Parser
Parse and return a single character of anything.
anything()  : Parser
Parse and return a single character of anything.
anySingleBut()  : Parser
Match any character but the given one.
oneOf()  : Parser
Succeeds if the current character is in the supplied list of characters. Returns the parsed character.
oneOfS()  : Parser
A compact form of 'oneOf'.
noneOf()  : Parser
The dual of 'oneOf'. Succeeds if the current character is not in the supplied list of characters. Returns the parsed character.
noneOfS()  : Parser
A compact form of 'noneOf'.
takeRest()  : Parser
Consume the rest of the input and return it as a string. This parser never fails, but may return the empty string.
nothing()  : Parser
Parse nothing, but still succeed.
everything()  : Parser
Parse everything; that is, consume the rest of the input until the end.
succeed()  : Parser
Always succeed, no matter what the input was.
fail()  : Parser
Always fail, no matter what the input was.
eof()  : Parser
Parse the end of the input

Functions

satisfy()

A parser that satisfies a predicate on a single token. Useful as a building block for writing things like char(), digit().

satisfy(callable $predicate) : Parser

..

Parameters
$predicate : callable
Tags
template
psalm-param

callable(string) : bool $predicate

psalm-return

Parser<T>

psalm-pure
Return values
Parser

skipWhile()

Skip 0 or more characters as long as the predicate holds.

skipWhile(callable $predicate) : Parser
Parameters
$predicate : callable
Tags
template
psalm-param

pure-callable(string) : bool $predicate

psalm-return

Parser

psalm-pure
Return values
Parser

skipWhile1()

Skip 1 or more characters as long as the predicate holds.

skipWhile1(callable $predicate) : Parser
Parameters
$predicate : callable
Tags
template
psalm-param

pure-callable(string) : bool $predicate

psalm-return

Parser

psalm-pure
Return values
Parser

takeWhile()

Keep parsing 0 or more characters as long as the predicate holds.

takeWhile(callable $predicate) : Parser
Parameters
$predicate : callable
Tags
template
psalm-param

pure-callable(string) : bool $predicate

psalm-return

Parser<T>

psalm-pure
Return values
Parser

takeWhile1()

Keep parsing 1 or more characters as long as the predicate holds.

takeWhile1(callable $predicate) : Parser
Parameters
$predicate : callable
Tags
template
psalm-param

pure-callable(string) : bool $predicate

psalm-return

Parser<T>

psalm-pure
Return values
Parser

anySingle()

Parse and return a single character of anything.

anySingle() : Parser
Tags
template
psalm-return

Parser<T>

psalm-pure
Return values
Parser

anything()

Parse and return a single character of anything.

anything() : Parser
Tags
TODO

This is an alias of anySingle. Should we get rid of one of them?

psalm-return

Parser

psalm-pure
Return values
Parser

anySingleBut()

Match any character but the given one.

anySingleBut(string $x) : Parser
Parameters
$x : string
Tags
psalm-return

Parser

template
psalm-pure
Return values
Parser

oneOf()

Succeeds if the current character is in the supplied list of characters. Returns the parsed character.

oneOf(array<string|int, mixed> $chars) : Parser
Parameters
$chars : array<string|int, mixed>
Tags
psalm-param

list $chars

psalm-return

Parser

template
psalm-pure
Return values
Parser

oneOfS()

A compact form of 'oneOf'.

oneOfS(string $chars) : Parser

oneOfS("abc") == oneOf(['a', 'b', 'c'])

Parameters
$chars : string
Tags
psalm-param

string $chars

psalm-return

Parser

psalm-pure
Return values
Parser

noneOf()

The dual of 'oneOf'. Succeeds if the current character is not in the supplied list of characters. Returns the parsed character.

noneOf(array<string|int, mixed> $chars) : Parser
Parameters
$chars : array<string|int, mixed>
Tags
psalm-param

list $chars

psalm-return

Parser

template
psalm-pure
Return values
Parser

noneOfS()

A compact form of 'noneOf'.

noneOfS(string $chars) : Parser

noneOfS("abc") == noneOf(['a', 'b', 'c'])

Parameters
$chars : string
Tags
psalm-param

string $chars

psalm-return

Parser

template
psalm-pure
Return values
Parser

takeRest()

Consume the rest of the input and return it as a string. This parser never fails, but may return the empty string.

takeRest() : Parser
Tags
psalm-return

Parser

template
psalm-pure
Return values
Parser

nothing()

Parse nothing, but still succeed.

nothing() : Parser

This serves as the zero parser in append() operations.

Tags
psalm-return

Parser

psalm-pure
Return values
Parser

everything()

Parse everything; that is, consume the rest of the input until the end.

everything() : Parser
Tags
psalm-pure
Return values
Parser

succeed()

Always succeed, no matter what the input was.

succeed() : Parser
Tags
psalm-pure
Return values
Parser

fail()

Always fail, no matter what the input was.

fail(string $label) : Parser
Parameters
$label : string
Tags
psalm-pure
Return values
Parser

eof()

Parse the end of the input

eof() : Parser
Tags
psalm-return

Parser<T>

template
psalm-pure
Return values
Parser

        
On this page

Search results