classBisonAlternativeReader
final class BisonAlternativeReader
Reads the alternatives on the right-hand side of one rule.
Bison lets the final semicolon be left out, so an alternative list also ends where the next rule begins — an identifier followed by a colon — or at the end of the section. All three endings complete the alternative in hand, which is why the reader looks two tokens ahead before it consumes anything.
Methods§
public function readAll(BisonTokenStream $stream): list<BisonAlternativeNode>Reads every alternative of the current rule.
Parameters
$stream | BisonTokenStream | Stream positioned on the first symbol after the colon |
Returns
list<BisonAlternativeNode> The alternatives, always at least oneTest cases 6
BisonAlternativeReaderTest::testReadAllDoesNotCarryAnActionIntoTheNextAlternativecovers and callsBisonAlternativeReaderTest::testReadAllKeepsEachAlternativesOwnActioncovers and callsBisonAlternativeReaderTest::testReadAllSplitsAlternativesOnThePipecovers and callsBisonAlternativeReaderTest::testReadAllStopsAtTheEndOfTheSectioncovers and callsBisonAlternativeReaderTest::testReadAllStopsWhereTheNextRuleBeginscovers and callsBisonAlternativeReaderTest::testReadAllTakesTheSymbolsUpToTheSemicoloncovers and calls
Called from 1
Calls 8
- new BisonAlternativeDraft line 34
- method-call BisonAlternativeReader::endsTheRule() line 38
- method-call BisonAlternativeDraft::complete() line 39
- method-call BisonTokenStream::peek() line 44
- class-const BisonLexeme::Semicolon() line 45
- method-call BisonTokenStream::next() line 46
- class-const BisonLexeme::Pipe() line 52
- method-call BisonAlternativeReader::readPart() line 58
public function endsTheRule(BisonTokenStream $stream): boolReports whether the alternative list is over without consuming anything.
Parameters
$stream | BisonTokenStream | Stream to look ahead in |
Returns
bool True at the end of the section or at the start of the next ruleTest cases 10
BisonAlternativeReaderTest::testEndsTheRuleConsumesNothingcovers and callsBisonAlternativeReaderTest::testEndsTheRuleReportsTheEndOfTheSectioncovers and callsBisonAlternativeReaderTest::testEndsTheRuleReportsTheStartOfTheNextRulecovers and callsBisonAlternativeReaderTest::testEndsTheRuleTreatsALoneNameAsPartOfTheAlternativecovers and callsBisonAlternativeReaderTest::testReadAllDoesNotCarryAnActionIntoTheNextAlternativecoversBisonAlternativeReaderTest::testReadAllKeepsEachAlternativesOwnActioncoversBisonAlternativeReaderTest::testReadAllSplitsAlternativesOnThePipecoversBisonAlternativeReaderTest::testReadAllStopsAtTheEndOfTheSectioncoversBisonAlternativeReaderTest::testReadAllStopsWhereTheNextRuleBeginscoversBisonAlternativeReaderTest::testReadAllTakesTheSymbolsUpToTheSemicoloncovers
Called from 1
Calls 6
- method-call BisonTokenStream::peek() line 71
- class-const BisonLexeme::Eof() line 73
- class-const BisonLexeme::PercentPercent() line 73
- class-const BisonLexeme::Identifier() line 77
- method-call BisonTokenStream::peekN() line 77
- class-const BisonLexeme::Colon() line 77
public function readPart(BisonTokenStream $stream, BisonAlternativeDraft $draft): voidReads one symbol, action or inline directive into the alternative.
Parameters
$stream | BisonTokenStream | Stream positioned on the part to read |
$draft | BisonAlternativeDraft | Alternative being assembled |
Test cases 9
BisonAlternativeReaderTest::testReadAllDoesNotCarryAnActionIntoTheNextAlternativecoversBisonAlternativeReaderTest::testReadAllKeepsEachAlternativesOwnActioncoversBisonAlternativeReaderTest::testReadAllSplitsAlternativesOnThePipecoversBisonAlternativeReaderTest::testReadAllStopsAtTheEndOfTheSectioncoversBisonAlternativeReaderTest::testReadAllStopsWhereTheNextRuleBeginscoversBisonAlternativeReaderTest::testReadAllTakesTheSymbolsUpToTheSemicoloncoversBisonAlternativeReaderTest::testReadPartAddsACharacterSymbolcovers and callsBisonAlternativeReaderTest::testReadPartAddsANamedSymbolcovers and callsBisonAlternativeReaderTest::testReadPartSkipsWhatBelongsToNoAlternativecovers and calls
Called from 1
Calls 22
- method-call BisonTokenStream::peek() line 88
- class-const BisonLexeme::Action() line 89
- method-call BisonAlternativeDraft::setAction() line 89
- method-call BisonTokenStream::nextString() line 89
- class-const BisonLexeme::Identifier() line 90
- method-call BisonAlternativeDraft::addSymbol() line 90
- new BisonSymbolNode line 91
- class-const BisonSymbolForm::Identifier() line 91
- class-const BisonLexeme::CharLiteral() line 93
- class-const BisonSymbolForm::CharLiteral() line 94
- class-const BisonLexeme::Directive() line 96
- method-call BisonAlternativeReader::readInlineDirective() line 96
- class-const BisonLexeme::Number() line 97
- class-const BisonLexeme::StringLiteral() line 98
- class-const BisonLexeme::TypeTag() line 99
- class-const BisonLexeme::Colon() line 100
- class-const BisonLexeme::Semicolon() line 101
- class-const BisonLexeme::Pipe() line 102
- class-const BisonLexeme::PercentPercent() line 103
- class-const BisonLexeme::Prologue() line 104
- class-const BisonLexeme::Eof() line 105
- method-call BisonTokenStream::next() line 105
public function readInlineDirective(
BisonTokenStream $stream,
BisonAlternativeDraft $draft,
): voidApplies %prec, %dprec or %merge to the alternative being read.
Parameters
$stream | BisonTokenStream | Stream positioned on the directive |
$draft | BisonAlternativeDraft | Alternative being assembled |
Test cases 2
Called from 1
Calls 7
- method-call BisonTokenStream::nextString() line 117
- method-call BisonAlternativeDraft::setPrecedenceSymbol() line 118
- method-call BisonAlternativeReader::readPrecedenceSymbol() line 118
- method-call BisonAlternativeDraft::setDynamicPrecedence() line 119
- method-call BisonAlternativeReader::readDynamicPrecedence() line 119
- method-call BisonAlternativeDraft::setMergeFunction() line 120
- method-call BisonAlternativeReader::readMergeFunction() line 120
public function readPrecedenceSymbol(BisonTokenStream $stream): string|nullReads the terminal whose precedence %prec borrows.
Parameters
$stream | BisonTokenStream | Stream positioned just after `%prec` |
Returns
string|null The terminal, or null when the directive named noneTest cases 3
Called from 1
Calls 3
- method-call BisonTokenStream::nextIf() line 134
- class-const BisonLexeme::Identifier() line 134
- class-const BisonLexeme::CharLiteral() line 134
public function readDynamicPrecedence(BisonTokenStream $stream): int|nullReads the rank %dprec assigns to this alternative.
Parameters
$stream | BisonTokenStream | Stream positioned just after `%dprec` |
Returns
int|null The rank, or null when the directive named noneTest cases 2
Called from 1
Calls 2
- method-call BisonTokenStream::nextIf() line 146
- class-const BisonLexeme::Number() line 146
public function readMergeFunction(BisonTokenStream $stream): string|nullReads the merge function %merge names for this alternative.
Parameters
$stream | BisonTokenStream | Stream positioned just after `%merge` |
Returns
string|null The function name, or null when the directive named noneTest cases 2
Called from 1
Calls 2
- method-call BisonTokenStream::nextIf() line 158
- class-const BisonLexeme::TypeTag() line 158
Test cases 23§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Dedicated tests 21
BisonAlternativeReaderTest::testEndsTheRuleConsumesNothingcovers and callsBisonAlternativeReaderTest::testEndsTheRuleReportsTheEndOfTheSectioncovers and callsBisonAlternativeReaderTest::testEndsTheRuleReportsTheStartOfTheNextRulecovers and callsBisonAlternativeReaderTest::testEndsTheRuleTreatsALoneNameAsPartOfTheAlternativecovers and callsBisonAlternativeReaderTest::testReadAllDoesNotCarryAnActionIntoTheNextAlternativecovers and callsBisonAlternativeReaderTest::testReadAllKeepsEachAlternativesOwnActioncovers and callsBisonAlternativeReaderTest::testReadAllSplitsAlternativesOnThePipecovers and callsBisonAlternativeReaderTest::testReadAllStopsAtTheEndOfTheSectioncovers and callsBisonAlternativeReaderTest::testReadAllStopsWhereTheNextRuleBeginscovers and callsBisonAlternativeReaderTest::testReadAllTakesTheSymbolsUpToTheSemicoloncovers and callsBisonAlternativeReaderTest::testReadDynamicPrecedenceReportsNothingWhenNoneIsNamedcovers and callsBisonAlternativeReaderTest::testReadDynamicPrecedenceTakesTheRankcovers and callsBisonAlternativeReaderTest::testReadInlineDirectiveAppliesPrecedencecovers and callsBisonAlternativeReaderTest::testReadInlineDirectiveIgnoresADirectiveItDoesNotModelcovers and callsBisonAlternativeReaderTest::testReadMergeFunctionReportsNothingWhenNoneIsNamedcovers and callsBisonAlternativeReaderTest::testReadMergeFunctionTakesTheTaggedNamecovers and callsBisonAlternativeReaderTest::testReadPartAddsACharacterSymbolcovers and callsBisonAlternativeReaderTest::testReadPartAddsANamedSymbolcovers and callsBisonAlternativeReaderTest::testReadPartSkipsWhatBelongsToNoAlternativecovers and callsBisonAlternativeReaderTest::testReadPrecedenceSymbolReportsNothingWhenNoneIsNamedcovers and callsBisonAlternativeReaderTest::testReadPrecedenceSymbolTakesANameOrACharactercovers and calls
Other tests reaching this symbol 2
BisonParserTestcallsBisonRuleReaderTestcalls