classBisonAlternativeDraft
final class BisonAlternativeDraft
The alternative currently being read.
An alternative is finished by whatever comes after it — a pipe, a semicolon, or the start of the next rule — rather than by a token of its own, so its parts accumulate until one of those appears. Holding them here means the reader flushes and starts over in one call instead of resetting five variables at each of the three places an alternative can end, which is where a forgotten reset would leave one alternative's action attached to the next.
Methods§
public function addSymbol(BisonSymbolNode $symbol): voidAppends a symbol to the right-hand side being read.
Parameters
$symbol | BisonSymbolNode | Symbol to append |
Test cases 2
Called from 2
public function setAction(string $action): voidAttaches the semantic action that runs when this alternative reduces.
Parameters
$action | string | Host-language code, without its braces |
Test cases 2
public function setPrecedenceSymbol(string|null $symbol): voidOverrides the alternative's precedence with that of a named terminal.
Parameters
$symbol | string|null | Terminal to take the precedence of, or null when `%prec` named none |
Test cases 2
public function setDynamicPrecedence(int|null $precedence): voidSets the dynamic precedence used to resolve an ambiguity at parse time.
Parameters
$precedence | int|null | The declared rank, or null when `%dprec` named none |
Test cases 2
public function setMergeFunction(string|null $function): voidSets the function that merges two ambiguous parses of this alternative.
Parameters
$function | string|null | Merge function name, or null when `%merge` named none |
Test cases 2
public function complete(): BisonAlternativeNodeTakes the alternative that has been read and starts a new one.
Returns
BisonAlternativeNode The completed alternativeTest cases 12
BisonAlternativeDraftTest::testAddSymbolKeepsTheOrderTheSymbolsWereReadcovers and callsBisonAlternativeDraftTest::testCompleteStartsANewAlternativeSoNothingCarriesOvercovers and callsBisonAlternativeDraftTest::testCompleteYieldsAnEmptyAlternativeWhenNothingWasReadcovers and callsBisonAlternativeDraftTest::testSetActionAttachesTheCodeThatRunsOnReductioncovers and callsBisonAlternativeDraftTest::testSetDynamicPrecedenceRecordsTheRankcovers and callsBisonAlternativeDraftTest::testSetMergeFunctionRecordsTheFunctionNamecovers and callsBisonAlternativeDraftTest::testSetPrecedenceSymbolRecordsTheBorrowedTerminalcovers and callsBisonAlternativeReaderTest::testReadInlineDirectiveAppliesPrecedencecallsBisonAlternativeReaderTest::testReadInlineDirectiveIgnoresADirectiveItDoesNotModelcallsBisonAlternativeReaderTest::testReadPartAddsACharacterSymbolcallsBisonAlternativeReaderTest::testReadPartAddsANamedSymbolcallsBisonAlternativeReaderTest::testReadPartSkipsWhatBelongsToNoAlternativecalls
Called from 3
- method-call SqlFaker\Compiler\Bison\Rule\BisonAlternativeReader::readAll() packages/sql-faker/src/Compiler/Bison/Rule/BisonAlternativeReader.php:39
- method-call SqlFaker\Compiler\Bison\Rule\BisonAlternativeReader::readAll() packages/sql-faker/src/Compiler/Bison/Rule/BisonAlternativeReader.php:47
- method-call SqlFaker\Compiler\Bison\Rule\BisonAlternativeReader::readAll() packages/sql-faker/src/Compiler/Bison/Rule/BisonAlternativeReader.php:54
Calls 1
Private surface 5§
Implementation details, listed for orientation only.
private list<BisonSymbolNode> $symbols = []private ?string $action = nullprivate ?string $precedenceSymbol = nullprivate ?int $dynamicPrecedence = nullprivate ?string $mergeFunction = nullTest cases 14§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Dedicated tests 7
BisonAlternativeDraftTest::testAddSymbolKeepsTheOrderTheSymbolsWereReadcovers and callsBisonAlternativeDraftTest::testCompleteStartsANewAlternativeSoNothingCarriesOvercovers and callsBisonAlternativeDraftTest::testCompleteYieldsAnEmptyAlternativeWhenNothingWasReadcovers and callsBisonAlternativeDraftTest::testSetActionAttachesTheCodeThatRunsOnReductioncovers and callsBisonAlternativeDraftTest::testSetDynamicPrecedenceRecordsTheRankcovers and callsBisonAlternativeDraftTest::testSetMergeFunctionRecordsTheFunctionNamecovers and callsBisonAlternativeDraftTest::testSetPrecedenceSymbolRecordsTheBorrowedTerminalcovers and calls
Other tests reaching this symbol 7
BisonParserTestcallsBisonAlternativeReaderTest::testReadInlineDirectiveAppliesPrecedencecallsBisonAlternativeReaderTest::testReadInlineDirectiveIgnoresADirectiveItDoesNotModelcallsBisonAlternativeReaderTest::testReadPartAddsACharacterSymbolcallsBisonAlternativeReaderTest::testReadPartAddsANamedSymbolcallsBisonAlternativeReaderTest::testReadPartSkipsWhatBelongsToNoAlternativecallsBisonRuleReaderTestcalls
Relations§
Instantiated in 1
Method calls 9
- method-call SqlFaker\Compiler\Bison\Rule\BisonAlternativeReader::readAll() packages/sql-faker/src/Compiler/Bison/Rule/BisonAlternativeReader.php:39
- method-call SqlFaker\Compiler\Bison\Rule\BisonAlternativeReader::readAll() packages/sql-faker/src/Compiler/Bison/Rule/BisonAlternativeReader.php:47
- method-call SqlFaker\Compiler\Bison\Rule\BisonAlternativeReader::readAll() packages/sql-faker/src/Compiler/Bison/Rule/BisonAlternativeReader.php:54
- method-call SqlFaker\Compiler\Bison\Rule\BisonAlternativeReader::readPart() packages/sql-faker/src/Compiler/Bison/Rule/BisonAlternativeReader.php:89
- method-call SqlFaker\Compiler\Bison\Rule\BisonAlternativeReader::readPart() packages/sql-faker/src/Compiler/Bison/Rule/BisonAlternativeReader.php:90
- method-call SqlFaker\Compiler\Bison\Rule\BisonAlternativeReader::readPart() packages/sql-faker/src/Compiler/Bison/Rule/BisonAlternativeReader.php:93
- method-call SqlFaker\Compiler\Bison\Rule\BisonAlternativeReader::readInlineDirective() packages/sql-faker/src/Compiler/Bison/Rule/BisonAlternativeReader.php:118
- method-call SqlFaker\Compiler\Bison\Rule\BisonAlternativeReader::readInlineDirective() packages/sql-faker/src/Compiler/Bison/Rule/BisonAlternativeReader.php:119
- method-call SqlFaker\Compiler\Bison\Rule\BisonAlternativeReader::readInlineDirective() packages/sql-faker/src/Compiler/Bison/Rule/BisonAlternativeReader.php:120