classBisonParser
final class BisonParser
Restricted visibility: declared "@visibility root". Code outside that scope must not name this declaration.
Reads a GNU Bison or Yacc grammar file into an AST.
A grammar file has three sections in a fixed order — declarations, rules, epilogue — so parsing is a sequence of three reads rather than a decision. Each section knows its own end, which is what lets this class say what a grammar file is without also saying how any part of it is spelled.
A file with no rules is refused. Unknown declarations are retained as source text so later passes can preserve constructs outside the AST model.
Methods§
public function __construct(
BisonPreambleReader|null $preamble = null,
BisonRuleReader|null $rules = null,
BisonStartSymbol|null $startSymbol = null,
)Parameters
$preamble | BisonPreambleReader|null | Reads the prologue and declarations |
$rules | BisonRuleReader|null | Reads the production rules |
$startSymbol | BisonStartSymbol|null | Decides which rule a derivation begins from |
Test cases 76
BisonParserTest::testParseActionBeforePreccoversBisonParserTest::testParseComplexGrammarcoversBisonParserTest::testParseDeclarationsSectionEndsAtEofcoversBisonParserTest::testParseDefineDirectiveWithIdentifierValuecoversBisonParserTest::testParseDefineDirectiveWithNumberValuecoversBisonParserTest::testParseDefineDirectiveWithoutIdentifiercoversBisonParserTest::testParseDefineDirectiveWithoutValuecoversBisonParserTest::testParseDefineDirectiveWithStringValuecoversBisonParserTest::testParseEmptyAlternativeWithoutEmptycoversBisonParserTest::testParseEmptyDeclarationsSectioncoversBisonParserTest::testParseEmptyTokenDirectivecoversBisonParserTest::testParseEpilogueMultipleTokensJoinedWithSpacecoversBisonParserTest::testParseExpectDirectivecoversBisonParserTest::testParseExpectDirectiveWithoutNumbercoversBisonParserTest::testParseFileNotFoundcoversBisonParserTest::testParseFileSuccesscoversBisonParserTest::testParseIdentifierNotFollowedByColonIsSkippedcoversBisonParserTest::testParseLexParamDirectivecoversBisonParserTest::testParseMidRuleActioncoversBisonParserTest::testParseMinimalGrammarcoversBisonParserTest::testParseMultipleActionsLastWinscoversBisonParserTest::testParseMultipleDeclarationscoversBisonParserTest::testParseMultipleProloguesLastWinscoversBisonParserTest::testParseMultipleRulescoversBisonParserTest::testParseMultipleRulesWithSameNamecoversBisonParserTest::testParseNoRulesThrowsExceptioncoversBisonParserTest::testParseParamDirectiveWithoutActioncoversBisonParserTest::testParseParseParamDirectivecoversBisonParserTest::testParsePrecBeforeActioncoversBisonParserTest::testParsePrecedenceDirective#leftcoversBisonParserTest::testParsePrecedenceDirective#nonassoccoversBisonParserTest::testParsePrecedenceDirective#precedencecoversBisonParserTest::testParsePrecedenceDirective#rightcoversBisonParserTest::testParsePrecedenceDirectiveSkipsNonSymbolscoversBisonParserTest::testParsePrecedenceDirectiveWithIdentifierscoversBisonParserTest::testParsePrecedenceDirectiveWithTypeTagcoversBisonParserTest::testParsePrologueAfterDeclarationscoversBisonParserTest::testParseRuleMultipleAlternativescoversBisonParserTest::testParseRuleSingleAlternativecoversBisonParserTest::testParseRuleSkipsUnknownTokenscoversBisonParserTest::testParseRulesSectionEndsAtEofcoversBisonParserTest::testParseRuleTerminatedByEofcoversBisonParserTest::testParseRuleTerminatedByNextRulecoversBisonParserTest::testParseRuleTerminatedByPercentPercentcoversBisonParserTest::testParseRuleTerminatedBySemicoloncoversBisonParserTest::testParseRuleWithActioncoversBisonParserTest::testParseRuleWithAllDirectivescoversBisonParserTest::testParseRuleWithCharLiteralSymbolcoversBisonParserTest::testParseRuleWithDpreccoversBisonParserTest::testParseRuleWithDprecAndMergecoversBisonParserTest::testParseRuleWithDprecWithoutNumbercoversBisonParserTest::testParseRuleWithEmptycoversBisonParserTest::testParseRuleWithMergecoversBisonParserTest::testParseRuleWithMergeWithoutTypeTagcoversBisonParserTest::testParseRuleWithPrecAndActioncoversBisonParserTest::testParseRuleWithPrecCharLiteralcoversBisonParserTest::testParseRuleWithPrecIdentifiercoversBisonParserTest::testParseRuleWithPrecWithoutSymbolcoversBisonParserTest::testParseSkipsUnknownTokensInDeclarationscoversBisonParserTest::testParseSkipsUnknownTokensInRulescoversBisonParserTest::testParseStartDirectivecoversBisonParserTest::testParseStartDirectiveWithoutIdentifiercoversBisonParserTest::testParseTokenDirectivecoversBisonParserTest::testParseTokenDirectiveSkipsNonIdentifierscoversBisonParserTest::testParseTokenDirectiveWithAliascoversBisonParserTest::testParseTokenDirectiveWithNumbercoversBisonParserTest::testParseTokenDirectiveWithNumberAndAliascoversBisonParserTest::testParseTokenDirectiveWithTypeTagcoversBisonParserTest::testParseTypeDirectivecoversBisonParserTest::testParseTypeDirectiveSkipsNonIdentifierscoversBisonParserTest::testParseTypeDirectiveWithoutTypeTagcoversBisonParserTest::testParseUnknownDirectivecoversBisonParserTest::testParseUnknownDirectiveInRulecoversBisonParserTest::testParseWithEpiloguecoversBisonParserTest::testParseWithoutEpiloguecoversBisonParserTest::testParseWithProloguecovers
Calls 3
public function parse(string $input): BisonAstReads grammar source text into an AST.
Parameters
$input | string | Bison grammar text |
Returns
BisonAst The grammar the text describesThrows
GrammarParseException When the text yields no production rulesTest cases 76
BisonParserTest::testParseActionBeforePreccovers and callsBisonParserTest::testParseComplexGrammarcovers and callsBisonParserTest::testParseDeclarationsSectionEndsAtEofcovers and callsBisonParserTest::testParseDefineDirectiveWithIdentifierValuecovers and callsBisonParserTest::testParseDefineDirectiveWithNumberValuecovers and callsBisonParserTest::testParseDefineDirectiveWithoutIdentifiercovers and callsBisonParserTest::testParseDefineDirectiveWithoutValuecovers and callsBisonParserTest::testParseDefineDirectiveWithStringValuecovers and callsBisonParserTest::testParseEmptyAlternativeWithoutEmptycovers and callsBisonParserTest::testParseEmptyDeclarationsSectioncovers and callsBisonParserTest::testParseEmptyTokenDirectivecovers and callsBisonParserTest::testParseEpilogueMultipleTokensJoinedWithSpacecovers and callsBisonParserTest::testParseExpectDirectivecovers and callsBisonParserTest::testParseExpectDirectiveWithoutNumbercovers and callsBisonParserTest::testParseFileSuccesscoversBisonParserTest::testParseIdentifierNotFollowedByColonIsSkippedcovers and callsBisonParserTest::testParseLexParamDirectivecovers and callsBisonParserTest::testParseMidRuleActioncovers and callsBisonParserTest::testParseMinimalGrammarcovers and callsBisonParserTest::testParseMultipleActionsLastWinscovers and callsBisonParserTest::testParseMultipleDeclarationscovers and callsBisonParserTest::testParseMultipleProloguesLastWinscovers and callsBisonParserTest::testParseMultipleRulescovers and callsBisonParserTest::testParseMultipleRulesWithSameNamecovers and callsBisonParserTest::testParseNoRulesThrowsExceptioncovers and callsBisonParserTest::testParseParamDirectiveWithoutActioncovers and callsBisonParserTest::testParseParseParamDirectivecovers and callsBisonParserTest::testParsePrecBeforeActioncovers and callsBisonParserTest::testParsePrecedenceDirectivecallsBisonParserTest::testParsePrecedenceDirective#leftcoversBisonParserTest::testParsePrecedenceDirective#nonassoccoversBisonParserTest::testParsePrecedenceDirective#precedencecoversBisonParserTest::testParsePrecedenceDirective#rightcoversBisonParserTest::testParsePrecedenceDirectiveSkipsNonSymbolscovers and callsBisonParserTest::testParsePrecedenceDirectiveWithIdentifierscovers and callsBisonParserTest::testParsePrecedenceDirectiveWithTypeTagcovers and callsBisonParserTest::testParsePrologueAfterDeclarationscovers and callsBisonParserTest::testParseRuleMultipleAlternativescovers and callsBisonParserTest::testParseRuleSingleAlternativecovers and callsBisonParserTest::testParseRuleSkipsUnknownTokenscovers and callsBisonParserTest::testParseRulesSectionEndsAtEofcovers and callsBisonParserTest::testParseRuleTerminatedByEofcovers and callsBisonParserTest::testParseRuleTerminatedByNextRulecovers and callsBisonParserTest::testParseRuleTerminatedByPercentPercentcovers and callsBisonParserTest::testParseRuleTerminatedBySemicoloncovers and callsBisonParserTest::testParseRuleWithActioncovers and callsBisonParserTest::testParseRuleWithAllDirectivescovers and callsBisonParserTest::testParseRuleWithCharLiteralSymbolcovers and callsBisonParserTest::testParseRuleWithDpreccovers and callsBisonParserTest::testParseRuleWithDprecAndMergecovers and callsBisonParserTest::testParseRuleWithDprecWithoutNumbercovers and callsBisonParserTest::testParseRuleWithEmptycovers and callsBisonParserTest::testParseRuleWithMergecovers and callsBisonParserTest::testParseRuleWithMergeWithoutTypeTagcovers and callsBisonParserTest::testParseRuleWithPrecAndActioncovers and callsBisonParserTest::testParseRuleWithPrecCharLiteralcovers and callsBisonParserTest::testParseRuleWithPrecIdentifiercovers and callsBisonParserTest::testParseRuleWithPrecWithoutSymbolcovers and callsBisonParserTest::testParseSkipsUnknownTokensInDeclarationscovers and callsBisonParserTest::testParseSkipsUnknownTokensInRulescovers and callsBisonParserTest::testParseStartDirectivecovers and callsBisonParserTest::testParseStartDirectiveWithoutIdentifiercovers and callsBisonParserTest::testParseTokenDirectivecovers and callsBisonParserTest::testParseTokenDirectiveSkipsNonIdentifierscovers and callsBisonParserTest::testParseTokenDirectiveWithAliascovers and callsBisonParserTest::testParseTokenDirectiveWithNumbercovers and callsBisonParserTest::testParseTokenDirectiveWithNumberAndAliascovers and callsBisonParserTest::testParseTokenDirectiveWithTypeTagcovers and callsBisonParserTest::testParseTypeDirectivecovers and callsBisonParserTest::testParseTypeDirectiveSkipsNonIdentifierscovers and callsBisonParserTest::testParseTypeDirectiveWithoutTypeTagcovers and callsBisonParserTest::testParseUnknownDirectivecovers and callsBisonParserTest::testParseUnknownDirectiveInRulecovers and callsBisonParserTest::testParseWithEpiloguecovers and callsBisonParserTest::testParseWithoutEpiloguecovers and callsBisonParserTest::testParseWithProloguecovers and calls
Called from 1
Calls 7
- static-call BisonTokenStream::over() line 62
- method-call BisonPreambleReader::read() line 64
- method-call BisonRuleReader::readAll() line 65
- function-call
trimline 66 - static-call GrammarParseException::noRulesParsed() line 69
- new BisonAst line 72
- method-call BisonStartSymbol::from() line 73
public function parseFile(string $path): BisonAstReads a grammar file from disk.
Parameters
$path | string | Path to a Bison grammar file |
Returns
BisonAst The grammar the file describesThrows
GrammarParseException When the file cannot be read, or yields no production rulesTest cases 2
BisonParserTest::testParseFileNotFoundcovers and callsBisonParserTest::testParseFileSuccesscovers and calls
Calls 4
- function-call
is_fileline 92 - static-call GrammarParseException::unreadableSource() line 93
- function-call
file_get_contentsline 96 - method-call BisonParser::parse() line 101
Private surface 3§
Implementation details, listed for orientation only.
private BisonPreambleReader $preambleprivate BisonRuleReader $rulesprivate BisonStartSymbol $startSymbolTest cases 77§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Dedicated tests 77
BisonParserTest::testParseActionBeforePreccovers and callsBisonParserTest::testParseComplexGrammarcovers and callsBisonParserTest::testParseDeclarationsSectionEndsAtEofcovers and callsBisonParserTest::testParseDefineDirectiveWithIdentifierValuecovers and callsBisonParserTest::testParseDefineDirectiveWithNumberValuecovers and callsBisonParserTest::testParseDefineDirectiveWithoutIdentifiercovers and callsBisonParserTest::testParseDefineDirectiveWithoutValuecovers and callsBisonParserTest::testParseDefineDirectiveWithStringValuecovers and callsBisonParserTest::testParseEmptyAlternativeWithoutEmptycovers and callsBisonParserTest::testParseEmptyDeclarationsSectioncovers and callsBisonParserTest::testParseEmptyTokenDirectivecovers and callsBisonParserTest::testParseEpilogueMultipleTokensJoinedWithSpacecovers and callsBisonParserTest::testParseExpectDirectivecovers and callsBisonParserTest::testParseExpectDirectiveWithoutNumbercovers and callsBisonParserTest::testParseFileNotFoundcovers and callsBisonParserTest::testParseFileSuccesscovers and callsBisonParserTest::testParseIdentifierNotFollowedByColonIsSkippedcovers and callsBisonParserTest::testParseLexParamDirectivecovers and callsBisonParserTest::testParseMidRuleActioncovers and callsBisonParserTest::testParseMinimalGrammarcovers and callsBisonParserTest::testParseMultipleActionsLastWinscovers and callsBisonParserTest::testParseMultipleDeclarationscovers and callsBisonParserTest::testParseMultipleProloguesLastWinscovers and callsBisonParserTest::testParseMultipleRulescovers and callsBisonParserTest::testParseMultipleRulesWithSameNamecovers and callsBisonParserTest::testParseNoRulesThrowsExceptioncovers and callsBisonParserTest::testParseParamDirectiveWithoutActioncovers and callsBisonParserTest::testParseParseParamDirectivecovers and callsBisonParserTest::testParsePrecBeforeActioncovers and callsBisonParserTest::testParsePrecedenceDirectivecallsBisonParserTest::testParsePrecedenceDirective#leftcoversBisonParserTest::testParsePrecedenceDirective#nonassoccoversBisonParserTest::testParsePrecedenceDirective#precedencecoversBisonParserTest::testParsePrecedenceDirective#rightcoversBisonParserTest::testParsePrecedenceDirectiveSkipsNonSymbolscovers and callsBisonParserTest::testParsePrecedenceDirectiveWithIdentifierscovers and callsBisonParserTest::testParsePrecedenceDirectiveWithTypeTagcovers and callsBisonParserTest::testParsePrologueAfterDeclarationscovers and callsBisonParserTest::testParseRuleMultipleAlternativescovers and callsBisonParserTest::testParseRuleSingleAlternativecovers and callsBisonParserTest::testParseRuleSkipsUnknownTokenscovers and callsBisonParserTest::testParseRulesSectionEndsAtEofcovers and callsBisonParserTest::testParseRuleTerminatedByEofcovers and callsBisonParserTest::testParseRuleTerminatedByNextRulecovers and callsBisonParserTest::testParseRuleTerminatedByPercentPercentcovers and callsBisonParserTest::testParseRuleTerminatedBySemicoloncovers and callsBisonParserTest::testParseRuleWithActioncovers and callsBisonParserTest::testParseRuleWithAllDirectivescovers and callsBisonParserTest::testParseRuleWithCharLiteralSymbolcovers and callsBisonParserTest::testParseRuleWithDpreccovers and callsBisonParserTest::testParseRuleWithDprecAndMergecovers and callsBisonParserTest::testParseRuleWithDprecWithoutNumbercovers and callsBisonParserTest::testParseRuleWithEmptycovers and callsBisonParserTest::testParseRuleWithMergecovers and callsBisonParserTest::testParseRuleWithMergeWithoutTypeTagcovers and callsBisonParserTest::testParseRuleWithPrecAndActioncovers and callsBisonParserTest::testParseRuleWithPrecCharLiteralcovers and callsBisonParserTest::testParseRuleWithPrecIdentifiercovers and callsBisonParserTest::testParseRuleWithPrecWithoutSymbolcovers and callsBisonParserTest::testParseSkipsUnknownTokensInDeclarationscovers and callsBisonParserTest::testParseSkipsUnknownTokensInRulescovers and callsBisonParserTest::testParseStartDirectivecovers and callsBisonParserTest::testParseStartDirectiveWithoutIdentifiercovers and callsBisonParserTest::testParseTokenDirectivecovers and callsBisonParserTest::testParseTokenDirectiveSkipsNonIdentifierscovers and callsBisonParserTest::testParseTokenDirectiveWithAliascovers and callsBisonParserTest::testParseTokenDirectiveWithNumbercovers and callsBisonParserTest::testParseTokenDirectiveWithNumberAndAliascovers and callsBisonParserTest::testParseTokenDirectiveWithTypeTagcovers and callsBisonParserTest::testParseTypeDirectivecovers and callsBisonParserTest::testParseTypeDirectiveSkipsNonIdentifierscovers and callsBisonParserTest::testParseTypeDirectiveWithoutTypeTagcovers and callsBisonParserTest::testParseUnknownDirectivecovers and callsBisonParserTest::testParseUnknownDirectiveInRulecovers and callsBisonParserTest::testParseWithEpiloguecovers and callsBisonParserTest::testParseWithoutEpiloguecovers and callsBisonParserTest::testParseWithProloguecovers and calls