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

Splits a grammar file into tokens as Lemon's Parse does.

Whitespace and comments are skipped. A token is a string in double quotes, a braced code block, a word of letters, digits and underscores starting with a letter or digit, the arrow ::=, a compound token |X or /X, or any single other character.

Methods§

public function __construct(private CodeReader $code = new \LemonParser\Scanner\CodeReader())

Parameters

$codeCodeReaderReads braced code
Calls 1
public function scan(string $source): non-empty-list<Token>

Scans the whole text.

Parameters

$sourcestringThe preprocessed grammar file

Returns

non-empty-list<Token> The tokens, ending with an end-of-file token
Test cases 49
Called from 1
Calls 7
public function skipTrivia(Cursor $cursor): void

Moves past whitespace and comments.

Parameters

$cursorCursorThe position
Test cases 2
Called from 1
Calls 7
public function next(Cursor $cursor): Token

Reads the token the cursor is at.

Parameters

$cursorCursorPositioned at the first byte of a token

Returns

Token The token

Throws

SyntaxException When a string or code block is not closed
Test cases 2
Called from 1
Calls 15

Private surface 1§

Implementation details, listed for orientation only.

private CodeReader $code = new \LemonParser\Scanner\CodeReader()

Test cases 56§

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

Dedicated tests 5
Other tests reaching this symbol 51

Relations§

Instantiated in 1
Method calls 1
Type declarations 1