final class RhsItem
Public API: explicitly declared with @visibility public.

One position on the right-hand side of a rule.

Usually one symbol, but Lemon lets several terminals share a position, written A|B|C; the position then matches any of them. An alias in parentheses names the value of the position in the rule's code.

Reading a multi-terminal positiondoctest
$file = (new \LemonParser\Parser())->parse("cmd ::= BEGIN|START trans_opt(X).\n");
    $items = $file->rules()[0]->items;
    [$items[0]->isMultiTerminal(), array_map(static fn ($symbol) => $symbol->name, $items[0]->symbols), $items[1]->alias] // => [true, ['BEGIN', 'START'], 'X']

Properties§

public non-empty-list<Symbol> $symbols
public string|null $alias

Methods§

public function __construct(public non-empty-list<Symbol> $symbols, public string|null $alias)

Parameters

$symbolsnon-empty-list<Symbol>The symbol, or the terminals that share the position
$aliasstring|nullThe name given to the position's value, or null
public function isMultiTerminal(): bool

Reports whether several terminals share the position.

Returns

bool True for `A|B` style positions
Test cases 1
Calls 1
public function location(): Location

Answers where the position begins.

Returns

Location Where the first symbol is written
Test cases 2

Test cases 16§

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

Dedicated tests 2
Other tests reaching this symbol 14

Relations§

Instantiated in 3
Type declarations 3