classBisonTrivia
final class BisonTrivia
The text between two lexemes that carries no token of its own.
Whitespace and comments may appear anywhere a lexeme may, so treating them as lexemes would mean every scanner returning "nothing this time" and the lexer looping until one of them returned something. Skipping them first keeps every scanner's contract honest: it is asked to read a lexeme, and it always produces one.
Inside a semantic action the same comment forms appear but a bare slash is division rather than a mistake, so recognising a comment and requiring one are offered separately.
Methods§
public function skipFrom(SourceCursor $cursor): voidSkips whitespace and comments until a lexeme starts or the source ends.
Parameters
$cursor | SourceCursor | Cursor to advance |
Throws
GrammarParseException When a slash opens neither comment formTest cases 4
BisonTriviaTest::testSkipFromLeavesALexemeAlonecovers and callsBisonTriviaTest::testSkipFromLeavesTheCursorOnTheFirstLexemecovers and callsBisonTriviaTest::testSkipFromReportsASlashThatOpensNoCommentcovers and callsBisonTriviaTest::testSkipFromRunsToTheEndWhenOnlyTriviaRemainscovers and calls
Called from 1
Calls 5
- method-call SourceCursor::skipWhitespace() line 36
- method-call BisonTrivia::skipCommentAt() line 38
- method-call SourceCursor::current() line 42
- static-call GrammarParseException::danglingSlash() line 43
- method-call SourceCursor::offset() line 43
public function skipCommentAt(SourceCursor $cursor): boolSkips one comment when the cursor sits on the start of one.
Parameters
$cursor | SourceCursor | Cursor to advance |
Returns
bool True when a comment was consumed, false when the cursor did not moveTest cases 8
BisonTriviaTest::testSkipCommentAtConsumesABlockCommentcovers and callsBisonTriviaTest::testSkipCommentAtConsumesALineCommentcovers and callsBisonTriviaTest::testSkipCommentAtLeavesALoneSlashInPlacecovers and callsBisonTriviaTest::testSkipCommentAtLeavesAnythingElseInPlacecovers and callsBisonTriviaTest::testSkipFromLeavesALexemeAlonecoversBisonTriviaTest::testSkipFromLeavesTheCursorOnTheFirstLexemecoversBisonTriviaTest::testSkipFromReportsASlashThatOpensNoCommentcoversBisonTriviaTest::testSkipFromRunsToTheEndWhenOnlyTriviaRemainscovers
Called from 2
Calls 4
- method-call SourceCursor::current() line 59
- method-call SourceCursor::peek() line 63
- method-call BisonTrivia::skipToEndOfLine() line 64
- method-call BisonTrivia::skipToCommentClose() line 65
public function skipToEndOfLine(SourceCursor $cursor): boolConsumes a line comment, stopping before the newline that ends it.
The newline is left behind because it is whitespace, and whitespace is skipped by the caller that owns the loop.
Parameters
$cursor | SourceCursor | Cursor positioned on the opening slash |
Returns
bool Always trueTest cases 4
Called from 1
Calls 2
- method-call SourceCursor::advance() line 82
- method-call SourceCursor::takeWhile() line 83
public function skipToCommentClose(SourceCursor $cursor): boolConsumes a block comment together with its terminator.
A comment left open by a truncated grammar ends at the end of the file.
Parameters
$cursor | SourceCursor | Cursor positioned on the opening slash |
Returns
bool Always trueTest cases 5
BisonTriviaTest::testSkipCommentAtConsumesABlockCommentcoversBisonTriviaTest::testSkipFromLeavesTheCursorOnTheFirstLexemecoversBisonTriviaTest::testSkipFromRunsToTheEndWhenOnlyTriviaRemainscoversBisonTriviaTest::testSkipToCommentCloseConsumesTheTerminatorcovers and callsBisonTriviaTest::testSkipToCommentCloseRunsToTheEndWhenNeverClosedcovers and calls
Called from 1
Calls 2
- method-call SourceCursor::advance() line 99
- method-call SourceCursor::takeUntil() line 100
Test cases 28§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Dedicated tests 11
BisonTriviaTest::testSkipCommentAtConsumesABlockCommentcovers and callsBisonTriviaTest::testSkipCommentAtConsumesALineCommentcovers and callsBisonTriviaTest::testSkipCommentAtLeavesALoneSlashInPlacecovers and callsBisonTriviaTest::testSkipCommentAtLeavesAnythingElseInPlacecovers and callsBisonTriviaTest::testSkipFromLeavesALexemeAlonecovers and callsBisonTriviaTest::testSkipFromLeavesTheCursorOnTheFirstLexemecovers and callsBisonTriviaTest::testSkipFromReportsASlashThatOpensNoCommentcovers and callsBisonTriviaTest::testSkipFromRunsToTheEndWhenOnlyTriviaRemainscovers and callsBisonTriviaTest::testSkipToCommentCloseConsumesTheTerminatorcovers and callsBisonTriviaTest::testSkipToCommentCloseRunsToTheEndWhenNeverClosedcovers and callsBisonTriviaTest::testSkipToEndOfLineStopsBeforeTheNewlinecovers and calls
Other tests reaching this symbol 17
BisonParserTestcallsBisonPreambleReaderTestcallsBisonDirectiveReaderChainTestcallsDefineDirectiveReaderTestcallsExpectDirectiveReaderTestcallsParamDirectiveReaderTestcallsPrecedenceDirectiveReaderTestcallsStartDirectiveReaderTestcallsTokenDirectiveReaderTestcallsTypeDirectiveReaderTestcallsUnknownDirectiveReaderTestcallsActionScannerTestcallsBisonLexerTestcallsBisonScannerChainTestcallsBisonTokenStreamTestcallsBisonAlternativeReaderTestcallsBisonRuleReaderTestcalls
Relations§
Instantiated in 2
Method calls 2
Type declarations 4
- type SqlFaker\Compiler\Bison\Lexer\ActionScanner packages/sql-faker/src/Compiler/Bison/Lexer/ActionScanner.php:24
- type SqlFaker\Compiler\Bison\Lexer\ActionScanner packages/sql-faker/src/Compiler/Bison/Lexer/ActionScanner.php:29
- type SqlFaker\Compiler\Bison\Lexer\BisonLexer packages/sql-faker/src/Compiler/Bison/Lexer/BisonLexer.php:30
- type SqlFaker\Compiler\Bison\Lexer\BisonLexer packages/sql-faker/src/Compiler/Bison/Lexer/BisonLexer.php:40