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

One right-hand side of a rule, as the sequence of items written between | separators.

Symbols, actions, predicates and modifiers are kept in the order they appear, so an action followed by more symbols is where Bison would put a mid-rule action.

Reading the symbols of an alternativedoctest
$file = (new \BisonParser\Parser())->parse("%%\nexpr: expr '+' { \$\$ = 1; } expr %prec PLUS ;\n");
    $alternative = $file->rules()[0]->alternatives[0];
    count($alternative->items) // => 5
    array_map(static fn ($symbol) => $symbol->value, $alternative->symbols()) // => ['expr', '+', 'expr']

Properties§

public list<RhsItem> $items
public Location $location

Methods§

public function __construct(public list<RhsItem> $items, public Location $location)

Parameters

$itemslist<RhsItem>Everything written on the right-hand side, in order
$locationLocationWhere the alternative begins, or where the `|` is for an empty one
public function symbols(): list<Symbol>

Answers the symbols of the right-hand side, leaving actions and modifiers out.

Returns

list<Symbol> The symbols in order
Test cases 1
Called from 1

Test cases 13§

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

Dedicated tests 1
Other tests reaching this symbol 12

Relations§

Instantiated in 1
Method calls 1
Type declarations 5