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

A whole Bison grammar file: the declarations, the grammar, and the epilogue.

The declarations are everything before the first %%. The grammar is everything between the two %%, in file order; Bison lets grammar declarations such as %type appear there among the rules, so the list holds both. The epilogue is the text after the second %%, if any.

Walking the rules of a filedoctest
$file = (new \BisonParser\Parser())->parse("%token NUM\n%%\nexpr: NUM | expr '+' NUM ;\n");
    count($file->rules()) // => 1
    $file->rules()[0]->name->value // => 'expr'

Properties§

public list<Declaration> $declarations
public list<Rule|Declaration> $grammar
public Epilogue|null $epilogue

Methods§

public function __construct(
    public list<Declaration> $declarations,
    public list<Rule|Declaration> $grammar,
    public Epilogue|null $epilogue,
)

Parameters

$declarationslist<Declaration>Declarations before the first `%%`, in file order
$grammarlist<Rule|Declaration>Rules and declarations between the two `%%`, in file order
$epilogueEpilogue|nullText after the second `%%`, or null when there is none
public function rules(): list<Rule>

Answers the rules of the grammar section, in file order.

Returns

list<Rule> The rules
Test cases 1
Called from 1
public function allDeclarations(): list<Declaration>

Answers every declaration, those of the declarations section first and those among the rules after.

Returns

list<Declaration> The declarations in file order
Test cases 1
Called from 2

Test cases 9§

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 7

Relations§

Instantiated in 1
Method calls 3
Type declarations 5