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

Splits a grammar file into the tokens Bison's own scanner produces.

This follows scan-gram.l: an identifier is looked past to see whether a colon or a bracketed name follows, a %name-prefix may be followed by =, a stray comma is whitespace, and everything after the second %% is one epilogue token.

Constants§

public const IDENTIFIER = '[.A-Za-z_][-.A-Za-z0-9_]*'

Pattern of an identifier: a letter, underscore or dot, then also digits and hyphens.

Methods§

public function __construct(
    private CodeReader $code = new \BisonParser\Scanner\CodeReader(),
    private Escapes $escapes = new \BisonParser\Scanner\Escapes(),
)

Parameters

$codeCodeReaderReads host code
$escapesEscapesDecodes literals
Calls 2
public function scan(string $source): list<Token>

Tokenizes a grammar file.

Parameters

$sourcestringContents of the file

Returns

list<Token> The tokens, ending with the end-of-file token

Throws

SyntaxException When the file holds something the grammar language does not allow
Test cases 57
Called from 1
Calls 12
public function next(Cursor $cursor): list<Token>

Reads the token, or the tokens, that begin at the cursor.

Parameters

$cursorCursorCursor positioned on a token

Returns

list<Token> One token, or an identifier and its bracketed name

Throws

SyntaxException When no token begins here or it never closes
Test cases 2
Called from 1
Calls 16
public function percent(Cursor $cursor, Location $location): Token

Reads what begins with a percent sign: a prologue, a section marker, a predicate or a directive.

Parameters

$cursorCursorCursor positioned on the percent sign
$locationLocationWhere it is

Returns

Token The token

Throws

SyntaxException When the directive is unknown or the code never closes
Test cases 3
Called from 1
Calls 16
public function identifier(Cursor $cursor, Location $location): list<Token>

Reads an identifier and looks past it for a bracketed name and a colon.

Parameters

$cursorCursorCursor positioned on the identifier
$locationLocationWhere it is

Returns

list<Token> The identifier, followed by its bracketed name when one follows it

Throws

SyntaxException When a bracketed name is malformed
Test cases 1
Called from 1
Calls 8
public function integer(Cursor $cursor, Location $location): Token

Reads a decimal or hexadecimal integer.

Parameters

$cursorCursorCursor positioned on the first digit
$locationLocationWhere it is

Returns

Token The integer, its text in decimal

Throws

SyntaxException When letters follow the digits
Test cases 6
Called from 1
Calls 11
public function literal(Cursor $cursor, Location $location): Token|null

Reads a character literal, a string, a translatable string, or a tag.

Parameters

$cursorCursorCursor positioned on the literal
$locationLocationWhere it is

Returns

Token|null The token, or null when no literal begins here

Throws

SyntaxException When the literal never closes or a character literal is not one byte
Test cases 5
Called from 1
Calls 13
public function tag(Cursor $cursor, Location $location): Token

Reads a tag, which may nest angle brackets as a C++ template does.

Parameters

$cursorCursorCursor positioned on the opening angle bracket
$locationLocationWhere it is

Returns

Token The tag

Throws

SyntaxException When the tag never closes
Test cases 2
Called from 1
Calls 10
public function punctuation(Cursor $cursor, Location $location): Token|null

Reads one punctuation byte.

Parameters

$cursorCursorCursor positioned on the byte
$locationLocationWhere it is

Returns

Token|null The token, or null when the byte is not punctuation the language has

Throws

SyntaxException When a bracketed name is malformed
Test cases 1
Called from 1
Calls 8

Private surface 2§

Implementation details, listed for orientation only.

private CodeReader $code = new \BisonParser\Scanner\CodeReader()
private Escapes $escapes = new \BisonParser\Scanner\Escapes()

Test cases 86§

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

Dedicated tests 29
Other tests reaching this symbol 57

Relations§

Instantiated in 1
Method calls 1
Type declarations 1