classGrammarFile
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.
$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> $declarationspublic list<Rule|Declaration> $grammarpublic Epilogue|null $epilogueMethods§
public function __construct(
public list<Declaration> $declarations,
public list<Rule|Declaration> $grammar,
public Epilogue|null $epilogue,
)Parameters
$declarations | list<Declaration> | Declarations before the first `%%`, in file order |
$grammar | list<Rule|Declaration> | Rules and declarations between the two `%%`, in file order |
$epilogue | Epilogue|null | Text after the second `%%`, or null when there is none |
public function rules(): list<Rule>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 orderTest cases 1
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
GrammarContextcallsTreeDumpercallsBisonGrammarCompilerTestcallsBisonGrammarReaderTestcallsParserTestcallsPrinterTest::testPrintcallsGrammarParserTestcalls
Relations§
Instantiated in 1
Method calls 3
- method-call SqlFaker\Compiler\Bison\BisonGrammarCompiler::declaredTokens() packages/sql-faker/src/Compiler/Bison/BisonGrammarCompiler.php:92
- method-call SqlFaker\Compiler\Bison\BisonGrammarCompiler::startSymbol() packages/sql-faker/src/Compiler/Bison/BisonGrammarCompiler.php:146
- method-call SqlFaker\Compiler\Bison\BisonGrammarCompiler::startSymbol() packages/sql-faker/src/Compiler/Bison/BisonGrammarCompiler.php:152
Type declarations 5
- type BisonParser\Parser packages/bison-parser/src/Parser.php:50
- type BisonParser\Printer\Printer packages/bison-parser/src/Printer/Printer.php:46
- type BisonParser\Syntax\GrammarParser packages/bison-parser/src/Syntax/GrammarParser.php:40
- type SqlFaker\Compiler\Bison\BisonGrammarCompiler packages/sql-faker/src/Compiler/Bison/BisonGrammarCompiler.php:89
- type SqlFaker\Compiler\Bison\BisonGrammarCompiler packages/sql-faker/src/Compiler/Bison/BisonGrammarCompiler.php:144