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 $mode,
    private ?int $ordinal = null,
)
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 9
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 10
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 22
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 6
Called from 28
Calls 2

Private surface 7§

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 array<array-key, string> $symbols
private self::CONTAINING|self::EXACT|self::NON_EMPTY|self::ORDINAL $mode
private ?int $ordinal = null

Test cases 65§

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

Dedicated tests 9
Other tests reaching this symbol 56

Relations§

Static calls 244
Type declarations 4