classGrammarReader
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
$declarations | DeclarationReader | Reads declarations |
$rules | RuleReader | Reads rules |
Calls 2
public function read(TokenStream $tokens): GrammarFileReads every item of the file.
Parameters
$tokens | TokenStream | The tokens |
Returns
GrammarFile The treeThrows
SyntaxException Where Lemon reports an errorTest cases 2
Called from 1
Calls 12
- new SymbolRegistry line 47
- method-call TokenStream::eof() line 51
- method-call TokenStream::next() line 52
- method-call DeclarationReader::read() line 54
- method-call RuleReader::read() line 58
- function-call
countline 60 - class-const TokenKind::Code() line 63
- method-call GrammarReader::code() line 64
- method-call GrammarReader::precedence() line 66
- new SyntaxException line 68
- new GrammarFile line 73
- function-call
array_valuesline 73
Attaches a code block to the previous rule.
Returns
Rule The rule with the code, or marked never to reduceThrows
SyntaxException When there is no rule or it already has codeTest cases 3
Called from 1
Calls 2
- new SyntaxException line 89
- new CodeBlock line 98
public function precedence(
Rule|null $previous,
TokenStream $tokens,
SymbolRegistry $registry,
): RuleReads TOKEN] after an opening bracket and marks the previous rule with it.
Parameters
$previous | Rule|null | The rule most recently completed |
$tokens | TokenStream | The rest |
$registry | SymbolRegistry | Symbols seen so far |
Returns
Rule The rule with the markThrows
SyntaxException Where Lemon reports an errorTest cases 5
Called from 1
Calls 4
- method-call TokenStream::next() line 114
- new SyntaxException line 116
- method-call SymbolRegistry::see() line 124
- new Symbol line 130
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
GrammarReaderTest::testCodecallsGrammarReaderTest::testCodeRejectsAMissingRulecallsGrammarReaderTest::testCodeRejectsASecondBlockcallsGrammarReaderTest::testPrecedencecallsGrammarReaderTest::testPrecedenceRejectsAMissingClosercallsGrammarReaderTest::testPrecedenceRejectsAMissingRulecallsGrammarReaderTest::testPrecedenceRejectsANonterminalcallsGrammarReaderTest::testPrecedenceRejectsASecondMarkcallsGrammarReaderTest::testReadcallsGrammarReaderTest::testReadRejectsAStrayTokencalls
Other tests reaching this symbol 3
LemonGrammarCompilerTestcallsLemonGrammarReaderTestcallsParserTestcalls