final class ProductionPattern
Restricted visibility: declared "@visibility root". Code outside that scope must not name this declaration.

Narrows a rule to the alternatives a caller will accept.

A grammar rule offers every alternative its parser recognises, and a caller generating a specific statement usually wants one of them. A pattern says which, either by naming symbols the alternative must contain, by naming the alternative outright, or by asking only that it write something.

Methods§

public function __construct(
    private array<array-key, string> $symbols,
    private self::CONTAINING|self::EXACT|self::NON_EMPTY|self::ORDINAL|self::ANY|self::ALL|self::NOT $mode,
    private ?int $ordinal = null,
    private list<self> $patterns = [],
)

Parameters

$symbolsarray<array-key, string>Symbols the pattern is written in terms of
$modeself::CONTAINING|self::EXACT|self::NON_EMPTY|self::ORDINAL|self::ANY|self::ALL|self::NOTHow those symbols are compared against an alternative
$ordinal?int
$patternslist<self>
public static function containing(string ...$symbols): self

Matches any alternative that contains all the named symbols.

Parameters

$symbolsstringSymbols the alternative must contain

Returns

self Pattern matching on containment
Test cases 19
Called from 65
Calls 2
public static function exactly(string ...$symbols): self

Matches only the alternative written exactly as the named symbols.

Parameters

$symbolsstringSymbols the alternative is made of, in order

Returns

self Pattern matching one alternative
Test cases 27
Called from 150
Calls 3
public static function at(int $ordinal): self

Selects one alternative, including when several have identical symbols.

Parameters

$ordinalint

Returns

self
Test cases 30
Called from 1
Calls 2
public static function nonEmpty(): self

Matches any alternative that writes at least one symbol.

Returns

self Pattern refusing only the empty alternative
Test cases 8
Called from 28
Calls 2
public static function anyOf(self $first, self ...$others): self

Retains alternatives accepted by at least one condition.

Parameters

$firstself
$othersself

Returns

self
Test cases 3
Calls 3
public static function allOf(self $first, self ...$others): self

Requires every condition at the same production.

Parameters

$firstself
$othersself

Returns

self
Test cases 2
Called from 1
Calls 3
public function matches(list<string> $symbols, ?int $ordinal = null): bool

Parameters

$symbolslist<string>
$ordinal?int

Returns

bool
Calls 9

Private surface 11§

Implementation details, listed for orientation only.

private const CONTAINING = 'containing'
private const EXACT = 'exact'
private const NON_EMPTY = 'non-empty'
private const ORDINAL = 'ordinal'
private const ANY = 'any'
private const ALL = 'all'
private const NOT = 'not'
private array<array-key, string> $symbols
private self::CONTAINING|self::EXACT|self::NON_EMPTY|self::ORDINAL|self::ANY|self::ALL|self::NOT $mode
private ?int $ordinal = null
private list<self> $patterns = []

Test cases 97§

Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.

Dedicated tests 14
Other tests reaching this symbol 83

Relations§

Static calls 245
Type declarations 6