classDirectiveScanner
final class DirectiveScanner
implements BisonScanner
Consumes the three lexemes a percent sign can open.
%% separates the grammar's sections, %{ ... %} wraps a prologue of host code, and anything else is a named directive such as %token. They share a starting character but nothing else, so the second character decides which of the three is being read.
Methods§
public function handles(string $character): boolReports whether a directive can start here.
Parameters
$character | string | A single character; never the empty string |
Returns
bool True for a percent signTest cases 1
DirectiveScannerTest::testHandlesClaimsOnlyAPercentSigncovers and calls
public function scan(SourceCursor $cursor): BisonTokenConsumes the section separator, prologue or directive name.
Parameters
$cursor | SourceCursor | Cursor positioned on the percent sign |
Returns
BisonToken The recognised tokenThrows
GrammarParseException When the percent sign is not followed by a directive nameTest cases 7
DirectiveScannerTest::testScanDirectiveNameKeepsTheLeadingPercentSigncovers and callsDirectiveScannerTest::testScanDirectiveNameReportsAPercentSignWithoutANamecovers and callsDirectiveScannerTest::testScanDispatchesOnTheCharacterAfterThePercentSigncovers and callsDirectiveScannerTest::testScanPrologueReadsTheCodeBetweenItsDelimiterscovers and callsDirectiveScannerTest::testScanPrologueRunsAnUnterminatedBodyToTheEndOfTheFilecovers and callsDirectiveScannerTest::testScanReportsTheOffsetTheDirectiveStartedAtcovers and callsDirectiveScannerTest::testScanSectionSeparatorReadsTwoPercentSignscovers and calls
Calls 4
- method-call SourceCursor::peek() line 47
- method-call DirectiveScanner::scanSectionSeparator() line 48
- method-call DirectiveScanner::scanPrologue() line 49
- method-call DirectiveScanner::scanDirectiveName() line 50
public function scanSectionSeparator(SourceCursor $cursor): BisonTokenConsumes the %% that separates two sections of the grammar.
Parameters
$cursor | SourceCursor | Cursor positioned on the first percent sign |
Returns
BisonToken The section separatorTest cases 2
Called from 1
Calls 4
- method-call SourceCursor::offset() line 63
- method-call SourceCursor::advance() line 64
- new BisonToken line 66
- class-const BisonLexeme::PercentPercent() line 66
public function scanPrologue(SourceCursor $cursor): BisonTokenConsumes a %{ ... %} prologue of host-language code.
An unterminated prologue takes the rest of the file as its body, which matches how Bison itself reads a grammar that was cut short.
Parameters
$cursor | SourceCursor | Cursor positioned on the percent sign |
Returns
BisonToken The prologue and its contentsTest cases 3
Called from 1
Calls 5
- method-call SourceCursor::offset() line 81
- method-call SourceCursor::advance() line 82
- new BisonToken line 84
- class-const BisonLexeme::Prologue() line 84
- method-call SourceCursor::takeUntil() line 84
public function scanDirectiveName(SourceCursor $cursor): BisonTokenConsumes a named directive such as %token or %parse-param.
Parameters
$cursor | SourceCursor | Cursor positioned on the percent sign |
Returns
BisonToken The directive including its leading percent signThrows
GrammarParseException When no name follows the percent signTest cases 4
DirectiveScannerTest::testScanDirectiveNameKeepsTheLeadingPercentSigncoversDirectiveScannerTest::testScanDirectiveNameReportsAPercentSignWithoutANamecoversDirectiveScannerTest::testScanDispatchesOnTheCharacterAfterThePercentSigncoversDirectiveScannerTest::testScanReportsTheOffsetTheDirectiveStartedAtcovers
Called from 1
Calls 7
- method-call SourceCursor::offset() line 98
- method-call SourceCursor::advance() line 99
- method-call SourceCursor::takeWhile() line 100
- function-call
preg_matchline 101 - static-call GrammarParseException::namelessDirective() line 105
- new BisonToken line 108
- class-const BisonLexeme::Directive() line 108
Test cases 25§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Dedicated tests 8
DirectiveScannerTest::testHandlesClaimsOnlyAPercentSigncovers and callsDirectiveScannerTest::testScanDirectiveNameKeepsTheLeadingPercentSigncovers and callsDirectiveScannerTest::testScanDirectiveNameReportsAPercentSignWithoutANamecovers and callsDirectiveScannerTest::testScanDispatchesOnTheCharacterAfterThePercentSigncovers and callsDirectiveScannerTest::testScanPrologueReadsTheCodeBetweenItsDelimiterscovers and callsDirectiveScannerTest::testScanPrologueRunsAnUnterminatedBodyToTheEndOfTheFilecovers and callsDirectiveScannerTest::testScanReportsTheOffsetTheDirectiveStartedAtcovers and callsDirectiveScannerTest::testScanSectionSeparatorReadsTwoPercentSignscovers and calls
Other tests reaching this symbol 17
BisonParserTestcallsBisonPreambleReaderTestcallsBisonDirectiveReaderChainTestcallsDefineDirectiveReaderTestcallsExpectDirectiveReaderTestcallsParamDirectiveReaderTestcallsPrecedenceDirectiveReaderTestcallsStartDirectiveReaderTestcallsTokenDirectiveReaderTestcallsTypeDirectiveReaderTestcallsUnknownDirectiveReaderTestcallsBisonLexerTestcallsBisonScannerChainTest::providerClaimedCharactercallsBisonScannerTest::providerScannercallsBisonTokenStreamTestcallsBisonAlternativeReaderTestcallsBisonRuleReaderTestcalls