final class BisonLexer
Restricted visibility: declared "@visibility root". Code outside that scope must not name this declaration.

Turns Bison grammar source into a stream of tokens, one call at a time.

The lexer owns no lexeme rule. It skips whitespace, asks the chain which scanner claims the character it is looking at, and hands over the cursor. A scanner that consumed only trivia returns the lexer to that same starting state, so comments cost a loop iteration instead of a recursive call.

Lookahead is owned by BisonTokenStream.

Methods§

public function __construct(
    string $source,
    BisonScannerChain|null $scanners = null,
    BisonTrivia|null $trivia = null,
)

Parameters

$sourcestringBison grammar text
$scannersBisonScannerChain|nullLexeme rules to recognise, defaulting to the Bison set
$triviaBisonTrivia|nullText between lexemes that carries no token
Test cases 86
Calls 3
public function scan(): BisonToken

Reads the next token, skipping any whitespace and comments before it.

Returns

BisonToken The next token, or an end-of-file token once the source runs out

Throws

GrammarParseException When no scanner recognises the character reached
Test cases 86
Called from 2
Calls 8
public function consumeRemaining(): string

Consumes the rest of the source as raw text.

The epilogue of a grammar file is host-language code that has no lexemes of its own, so it is taken whole rather than scanned.

Returns

string Everything the cursor has not passed over yet
Test cases 77
Called from 1
Calls 1

Private surface 3§

Implementation details, listed for orientation only.

private SourceCursor $cursor
private BisonScannerChain $scanners
private BisonTrivia $trivia

Test cases 99§

Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.

Dedicated tests 11
Other tests reaching this symbol 88

Relations§

Instantiated in 1
Method calls 3
Type declarations 2