classRuleParser
final class RuleParser
Reads one rule, following the rules and rhs rules of parse-gram.y.
An alternative ends at |, at ;, or where the next rule or a declaration begins, which is how Bison reads a rule that omits its semicolon. Extra semicolons after a rule are accepted as Bison accepts them.
Methods§
public function __construct(
private SymbolListParser $symbols = new \BisonParser\Syntax\SymbolListParser(),
private DeclarationParser $lines = new \BisonParser\Syntax\DeclarationParser(),
)Parameters
$symbols | SymbolListParser | Turns symbol tokens into symbols |
$lines | DeclarationParser | Turns `#line` tokens into nodes |
Calls 2
public function parse(TokenStream $tokens): RuleReads the rule that begins at the current token.
Parameters
$tokens | TokenStream | Tokens positioned on the rule's left-hand side |
Returns
Rule The ruleThrows
SyntaxException When the rule is not written as `name: alternatives`Test cases 7
RuleParserTest::testCheckEmptyRejectsAMidrulePredicatecallsRuleParserTest::testCheckEmptyRejectsASymbolcallsRuleParserTest::testParsecallsRuleParserTest::testParseAcceptsSemicolonsBetweenAlternativescallsRuleParserTest::testParseEndsAtTheNextRulecallsRuleParserTest::testParseRejectsAMissingColoncallsRuleParserTest::testParseRejectsANonRulecalls
Called from 1
Calls 11
- method-call TokenStream::expect() line 55
- class-const TokenKind::IdentifierColon() line 55
- method-call TokenStream::accept() line 56
- class-const TokenKind::BracketedIdentifier() line 56
- class-const TokenKind::Colon() line 57
- method-call RuleParser::alternative() line 58
- method-call TokenStream::peek() line 58
- class-const TokenKind::Pipe() line 60
- class-const TokenKind::Semicolon() line 63
- new Rule line 68
- method-call SymbolListParser::symbol() line 68
public function alternative(TokenStream $tokens, Location $at): AlternativeReads the items of one alternative.
Parameters
$tokens | TokenStream | Tokens positioned on the first item, or on what ends the alternative |
$at | Location | Where the alternative begins |
Returns
Alternative The alternativeThrows
SyntaxException When an item is malformedTest cases 1
Called from 2
Calls 3
- method-call RuleParser::item() line 84
- method-call RuleParser::checkEmpty() line 87
- new Alternative line 89
public function checkEmpty(list<RhsItem> $items): voidBison rejects %empty on a rule that has components: a symbol, or an
action that is followed by another item and hence becomes a midrule
symbol.
Parameters
$items | list<RhsItem> |
Test cases 1
Called from 1
Calls 1
- static-call SyntaxException::invalid() line 110
public function item(TokenStream $tokens): RhsItem|nullReads one item of a right-hand side.
Parameters
$tokens | TokenStream | Tokens positioned on the item |
Returns
RhsItem|null The item, or null when the alternative ends hereThrows
SyntaxException When the item is malformedTest cases 2
Called from 1
Calls 16
- method-call TokenStream::peek() line 127
- method-call SymbolListParser::startsSymbol() line 128
- method-call TokenStream::next() line 129
- new SymbolItem line 131
- method-call SymbolListParser::symbol() line 131
- method-call TokenStream::accept() line 131
- class-const TokenKind::BracketedIdentifier() line 131
- class-const TokenKind::Tag() line 133
- class-const TokenKind::Code() line 133
- method-call RuleParser::action() line 134
- class-const TokenKind::Predicate() line 136
- new Predicate line 139
- class-const TokenKind::Line() line 141
- method-call DeclarationParser::line() line 144
- class-const TokenKind::Directive() line 146
- method-call RuleParser::modifier() line 150
public function action(TokenStream $tokens): ActionReads a braced action with its optional tag and name.
Parameters
$tokens | TokenStream | Tokens positioned on the tag or the code |
Returns
Action The actionThrows
SyntaxException When a tag is not followed by braced codeTest cases 2
Called from 1
Calls 7
- method-call TokenStream::next() line 164
- class-const TokenKind::Tag() line 167
- method-call TokenStream::expect() line 169
- class-const TokenKind::Code() line 169
- new Action line 172
- method-call TokenStream::accept() line 172
- class-const TokenKind::BracketedIdentifier() line 172
public function modifier(TokenStream $tokens): RhsItem|nullReads a %-modifier of a right-hand side.
Parameters
$tokens | TokenStream | Tokens positioned on the directive |
Returns
RhsItem|null The modifier, or null when the directive begins a declaration insteadThrows
SyntaxException When the modifier lacks its argumentTest cases 3
Called from 1
Calls 13
- method-call TokenStream::peek() line 186
- function-call
in_arrayline 188 - method-call TokenStream::next() line 191
- new EmptyItem line 194
- new PrecItem line 195
- method-call SymbolListParser::symbol() line 195
- method-call RuleParser::symbolToken() line 195
- new DprecItem line 196
- method-call TokenStream::expect() line 196
- class-const TokenKind::Integer() line 196
- new MergeItem line 197
- class-const TokenKind::Tag() line 197
- new ExpectItem line 198
public function symbolToken(TokenStream $tokens): TokenConsumes the symbol token that must follow %prec.
Parameters
$tokens | TokenStream | Tokens positioned after `%prec` |
Returns
Token The symbol tokenThrows
SyntaxException When no symbol followsTest cases 2
Called from 1
Calls 4
- method-call TokenStream::peek() line 213
- method-call SymbolListParser::startsSymbol() line 214
- static-call SyntaxException::unexpected() line 215
- method-call TokenStream::next() line 218
Private surface 2§
Implementation details, listed for orientation only.
private SymbolListParser $symbols = new \BisonParser\Syntax\SymbolListParser()private DeclarationParser $lines = new \BisonParser\Syntax\DeclarationParser()Test cases 22§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Dedicated tests 18
RuleParserTest::testActioncallsRuleParserTest::testActionRejectsATagWithoutCodecallsRuleParserTest::testAlternativecallsRuleParserTest::testCheckEmptycallsRuleParserTest::testCheckEmptyRejectsAMidrulePredicatecallsRuleParserTest::testCheckEmptyRejectsASymbolcallsRuleParserTest::testItemcallsRuleParserTest::testItemKeepsALineDirectivecallsRuleParserTest::testModifiercallsRuleParserTest::testModifierRejectsADprecWithoutANumbercallsRuleParserTest::testModifierRejectsAMergeWithoutATagcallsRuleParserTest::testParsecallsRuleParserTest::testParseAcceptsSemicolonsBetweenAlternativescallsRuleParserTest::testParseEndsAtTheNextRulecallsRuleParserTest::testParseRejectsAMissingColoncallsRuleParserTest::testParseRejectsANonRulecallsRuleParserTest::testSymbolTokencallsRuleParserTest::testSymbolTokenRejectsANonSymbolcalls
Other tests reaching this symbol 4
BisonGrammarCompilerTestcallsBisonGrammarReaderTestcallsParserTestcallsGrammarParserTestcalls