classRuleReader
final class RuleReader
Restricted visibility: declared "@visibility root". Code outside that scope must not name this declaration.
Reads a rule from its left-hand side to its period, as Lemon's rule states do.
Methods§
public function read(Token $lhs, TokenStream $tokens, SymbolRegistry $registry): RuleReads a rule whose left-hand side has been taken.
Parameters
$lhs | Token | The nonterminal token |
$tokens | TokenStream | The rest |
$registry | SymbolRegistry | Symbols seen so far |
Returns
Rule The rule, without precedence mark or codeThrows
SyntaxException Where Lemon reports an errorTest cases 6
RuleReaderTest::testReadcallsRuleReaderTest::testReadAcceptsAnEmptyRightHandSidecallsRuleReaderTest::testReadRejectsACompoundAtTheStartcallsRuleReaderTest::testReadRejectsALowerCaseCompoundcallsRuleReaderTest::testReadRejectsAnIllegalCharactercallsRuleReaderTest::testReadRejectsTheEndOfTheFilecalls
Called from 1
Calls 13
- method-call SymbolRegistry::see() line 34
- method-call RuleReader::head() line 35
- method-call TokenStream::next() line 38
- new RhsItem line 44
- new Symbol line 44
- class-const TokenKind::Compound() line 45
- function-call
ctype_upperline 45 - function-call
countline 47 - method-call RuleReader::compound() line 47
- method-call RuleReader::alias() line 49
- class-const TokenKind::End() line 50
- new SyntaxException line 51
- new Rule line 57
public function head(Token $lhs, TokenStream $tokens): string|nullReads what follows the left-hand side up to and including ::=.
Parameters
$lhs | Token | The nonterminal token |
$tokens | TokenStream | The rest |
Returns
string|null The alias of the left-hand side, or nullThrows
SyntaxException Where Lemon reports an errorTest cases 5
Called from 1
Calls 3
- method-call TokenStream::next() line 72
- class-const TokenKind::Arrow() line 73
- new SyntaxException line 77
Adds a terminal to the position before it, making a multi-terminal.
Returns
RhsItem The position with the terminal addedThrows
SyntaxException When the position holds a nonterminalTest cases 2
Called from 1
public function alias(
RhsItem $item,
TokenStream $tokens,
Token $lhs,
string|null $lhsAlias,
): RhsItemReads name) after an opening parenthesis and names the position before it.
Parameters
$item | RhsItem | The position |
$tokens | TokenStream | The rest |
$lhs | Token | The rule's nonterminal, for messages |
$lhsAlias | string|null | The rule's alias, for messages |
Returns
RhsItem The named positionThrows
SyntaxException Where Lemon reports an errorTest cases 3
Called from 1
Calls 3
- method-call TokenStream::next() line 128
- new SyntaxException line 130
- new RhsItem line 137
Test cases 20§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Dedicated tests 16
RuleReaderTest::testAliascallsRuleReaderTest::testAliasRejectsABadNamecallsRuleReaderTest::testAliasRejectsAMissingClosercallsRuleReaderTest::testCompoundcallsRuleReaderTest::testCompoundRejectsANonterminalcallsRuleReaderTest::testHeadcallsRuleReaderTest::testHeadRejectsABadAliascallsRuleReaderTest::testHeadRejectsAMissingArrowcallsRuleReaderTest::testHeadRejectsAMissingArrowAfterTheAliascallsRuleReaderTest::testHeadRejectsAnUnclosedAliascallsRuleReaderTest::testReadcallsRuleReaderTest::testReadAcceptsAnEmptyRightHandSidecallsRuleReaderTest::testReadRejectsACompoundAtTheStartcallsRuleReaderTest::testReadRejectsALowerCaseCompoundcallsRuleReaderTest::testReadRejectsAnIllegalCharactercallsRuleReaderTest::testReadRejectsTheEndOfTheFilecalls
Other tests reaching this symbol 4
LemonGrammarCompilerTestcallsLemonGrammarReaderTestcallsParserTestcallsGrammarReaderTestcalls