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

Represents a single production (right-hand side) in a grammar rule.

A production is a sequence of symbols that a non-terminal can expand to.

Properties§

public list<Symbol> $symbols
public ?int $ordinal = null
public ?string $origin = null

Methods§

public function __construct(
    public list<Symbol> $symbols,
    public ?int $ordinal = null,
    public ?string $origin = null,
)

Parameters

$symbolslist<Symbol>Sequence of terminal and non-terminal symbols
$ordinal?int
$origin?string
Test cases 1153
public function hasTerminal(string $value): bool

Reports whether one of the symbols is a given terminal.

Parameters

$valuestringTerminal to look for

Returns

bool True when the production writes that terminal
Test cases 2
public function hasNonTerminal(string $value): bool

Reports whether one of the symbols expands to a given rule.

Parameters

$valuestringNon-terminal to look for

Returns

bool True when the production expands to that rule
Test cases 2
public function hasAnyTerminal(): bool

Reports whether the production writes anything at all by itself.

A production made only of non-terminals writes nothing until those are expanded, which is what tells a rule apart from one that anchors on a keyword.

Returns

bool True when at least one symbol is a terminal
Test cases 2
public function terminalAt(int $index): Terminal|null

Answers the symbol at one position when it is a terminal.

Parameters

$indexintPosition in the production

Returns

Terminal|null Terminal at that position, or null when it is absent or a non-terminal
Test cases 283
public function nonTerminalAt(int $index): NonTerminal|null

Answers the symbol at one position when it is a non-terminal.

Parameters

$indexintPosition in the production

Returns

NonTerminal|null Non-terminal at that position, or null when it is absent or a terminal
Test cases 283
public function nonTerminalNames(): list<string>

Answers the rules the production expands to, in order.

Returns

list<string> Non-terminal names in the order they are written
Test cases 1

Test cases 1436§

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 1422

Relations§

Instantiated in 7
Type declarations 13