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

Reads a whole grammar file, as Lemon's WAITING_FOR_DECL_OR_RULE state does.

A % starts a declaration, a nonterminal starts a rule, and a code block or a [TOKEN] mark attaches to the rule most recently completed, even when declarations come between.

Methods§

public function __construct(
    private DeclarationReader $declarations = new \LemonParser\Syntax\DeclarationReader(),
    private RuleReader $rules = new \LemonParser\Syntax\RuleReader(),
)

Parameters

$declarationsDeclarationReaderReads declarations
$rulesRuleReaderReads rules
Calls 2
public function read(TokenStream $tokens): GrammarFile

Reads every item of the file.

Parameters

$tokensTokenStreamThe tokens

Returns

GrammarFile The tree

Throws

SyntaxException Where Lemon reports an error
Test cases 2
Called from 1
Calls 12
public function code(Rule|null $previous, Token $code): Rule

Attaches a code block to the previous rule.

Parameters

$previousRule|nullThe rule most recently completed
$codeTokenThe code token

Returns

Rule The rule with the code, or marked never to reduce

Throws

SyntaxException When there is no rule or it already has code
Test cases 3
Called from 1
Calls 2
public function precedence(
    Rule|null $previous,
    TokenStream $tokens,
    SymbolRegistry $registry,
): Rule

Reads TOKEN] after an opening bracket and marks the previous rule with it.

Parameters

$previousRule|nullThe rule most recently completed
$tokensTokenStreamThe rest
$registrySymbolRegistrySymbols seen so far

Returns

Rule The rule with the mark

Throws

SyntaxException Where Lemon reports an error
Test cases 5
Called from 1
Calls 4

Private surface 2§

Implementation details, listed for orientation only.

private DeclarationReader $declarations = new \LemonParser\Syntax\DeclarationReader()
private RuleReader $rules = new \LemonParser\Syntax\RuleReader()

Test cases 13§

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

Dedicated tests 10
Other tests reaching this symbol 3

Relations§

Instantiated in 1
Method calls 1
Type declarations 1