classSymbolListParser
final class SymbolListParser
Reads the symbol lists that follow %token, %nterm, %type, %start, %left and their kin.
The lists differ in what a string means: after %token it is the alias of the identifier before it, after %left and %type it is a token of its own, and after %token it may also carry a token number.
Methods§
public function tokenDeclarations(TokenStream $tokens): list<SymbolEntry>Reads the entries of a %token list: an identifier or character literal, its number, and the string that aliases it.
Parameters
$tokens | TokenStream | Tokens positioned after the directive |
Returns
list<SymbolEntry> The entries, at least oneThrows
SyntaxException When the list is empty or malformedTest cases 2
Called from 1
Calls 3
- method-call SymbolListParser::entries() line 38
- class-const SymbolKind::Identifier() line 38
- class-const SymbolKind::CharLiteral() line 38
public function ntermDeclarations(TokenStream $tokens): list<SymbolEntry>Reads the entries of a %nterm list: identifiers only, under optional tags.
Parameters
$tokens | TokenStream | Tokens positioned after the directive |
Returns
list<SymbolEntry> The entries, at least oneThrows
SyntaxException When the list is empty or malformedTest cases 4
Called from 1
Calls 2
- method-call SymbolListParser::entries() line 52
- class-const SymbolKind::Identifier() line 52
public function precedenceDeclarations(TokenStream $tokens): list<SymbolEntry>Reads the entries of a precedence list, where a string is a token of its own.
Parameters
$tokens | TokenStream | Tokens positioned after the directive |
Returns
list<SymbolEntry> The entries, at least oneThrows
SyntaxException When the list is empty or malformedTest cases 1
Called from 1
Calls 4
- method-call SymbolListParser::entries() line 66
- class-const SymbolKind::Identifier() line 66
- class-const SymbolKind::CharLiteral() line 66
- class-const SymbolKind::String() line 66
public function typeDeclarations(TokenStream $tokens): list<SymbolEntry>Reads the entries of a %type list, plain symbols under optional tags.
Parameters
$tokens | TokenStream | Tokens positioned after the directive |
Returns
list<SymbolEntry> The entries, at least oneThrows
SyntaxException When the list is empty or malformedTest cases 1
Called from 1
Calls 4
- method-call SymbolListParser::entries() line 80
- class-const SymbolKind::Identifier() line 80
- class-const SymbolKind::CharLiteral() line 80
- class-const SymbolKind::String() line 80
public function entries(
TokenStream $tokens,
bool $numbered,
bool $aliased,
list<SymbolKind> $starts,
): list<SymbolEntry>Reads tagged entries until something that is neither a tag nor a symbol.
Parameters
$tokens | TokenStream | Tokens positioned at the list |
$numbered | bool | Whether an integer may follow an identifier |
$aliased | bool | Whether a string after an identifier is its alias |
$starts | list<SymbolKind> | The kinds of symbol that may start an entry |
Returns
list<SymbolEntry> The entries, at least oneThrows
SyntaxException When the list is empty, a tag has no symbol after it, or an entry starts with a symbol of another kindTest cases 5
Called from 4
- method-call BisonParser\Syntax\SymbolListParser::tokenDeclarations() packages/bison-parser/src/Syntax/SymbolListParser.php:38
- method-call BisonParser\Syntax\SymbolListParser::ntermDeclarations() packages/bison-parser/src/Syntax/SymbolListParser.php:52
- method-call BisonParser\Syntax\SymbolListParser::precedenceDeclarations() packages/bison-parser/src/Syntax/SymbolListParser.php:66
- method-call BisonParser\Syntax\SymbolListParser::typeDeclarations() packages/bison-parser/src/Syntax/SymbolListParser.php:80
Calls 10
- method-call SymbolListParser::passesLine() line 100
- method-call TokenStream::accept() line 103
- class-const TokenKind::Tag() line 103
- method-call SymbolListParser::startsSymbol() line 106
- method-call TokenStream::peek() line 106
- static-call SyntaxException::unexpected() line 107
- function-call
in_arrayline 114 - method-call SymbolListParser::kind() line 114
- method-call SymbolListParser::describe() line 115
- method-call SymbolListParser::entry() line 117
public function entry(
TokenStream $tokens,
string|null $tag,
bool $numbered,
bool $aliased,
): SymbolEntryReads one entry: a symbol with the number and alias the list allows.
Parameters
$tokens | TokenStream | Tokens positioned on the symbol |
$tag | string|null | Tag in force |
$numbered | bool | Whether an integer may follow an identifier |
$aliased | bool | Whether a string after an identifier is its alias |
Returns
SymbolEntry The entryTest cases 1
Called from 1
Calls 8
- method-call SymbolListParser::symbol() line 138
- method-call TokenStream::next() line 138
- method-call TokenStream::accept() line 141
- class-const TokenKind::Integer() line 141
- class-const TokenKind::String() line 146
- class-const TokenKind::TranslatableString() line 146
- new Alias line 147
- new SymbolEntry line 150
public function symbols(TokenStream $tokens): list<Symbol>Reads the symbols that follow %start.
Parameters
$tokens | TokenStream | Tokens positioned after the directive |
Returns
list<Symbol> The symbols, at least oneThrows
SyntaxException When no symbol followsTest cases 2
Called from 1
Calls 6
- method-call SymbolListParser::startsSymbol() line 165
- method-call TokenStream::peek() line 165
- method-call SymbolListParser::passesLine() line 165
- method-call SymbolListParser::symbol() line 167
- method-call TokenStream::next() line 167
- static-call SyntaxException::unexpected() line 171
public function targets(TokenStream $tokens): list<Symbol|Tag>Reads the symbols and tags that follow the code of %destructor or %printer.
Parameters
$tokens | TokenStream | Tokens positioned after the code |
Throws
SyntaxException When no target followsTest cases 2
Called from 1
Calls 10
- method-call TokenStream::peek() line 190
- method-call SymbolListParser::passesLine() line 191
- method-call SymbolListParser::startsSymbol() line 194
- method-call SymbolListParser::symbol() line 195
- method-call TokenStream::next() line 195
- class-const TokenKind::Tag() line 196
- class-const TokenKind::TagAny() line 196
- class-const TokenKind::TagNone() line 196
- new Tag line 197
- static-call SyntaxException::unexpected() line 203
public function passesLine(TokenStream $tokens): boolPasses over a #line directive that falls inside a list, where Bison treats it as whitespace.
A directive followed by anything else ends the list and is kept as a node of its own, so only a directive between two entries is lost.
Parameters
$tokens | TokenStream | The tokens |
Returns
bool True when a directive was passed overTest cases 1
Called from 3
- method-call BisonParser\Syntax\SymbolListParser::entries() packages/bison-parser/src/Syntax/SymbolListParser.php:100
- method-call BisonParser\Syntax\SymbolListParser::symbols() packages/bison-parser/src/Syntax/SymbolListParser.php:165
- method-call BisonParser\Syntax\SymbolListParser::targets() packages/bison-parser/src/Syntax/SymbolListParser.php:191
Calls 8
- method-call TokenStream::peek() line 221
- method-call TokenStream::is() line 222
- class-const TokenKind::Line() line 222
- method-call SymbolListParser::startsSymbol() line 222
- class-const TokenKind::Tag() line 222
- class-const TokenKind::TagAny() line 222
- class-const TokenKind::TagNone() line 222
- method-call TokenStream::next() line 225
public function startsSymbol(Token $token): boolReports whether a token begins a symbol.
Parameters
$token | Token | Token to look at |
Returns
bool True for an identifier, a character literal or a stringTest cases 1
Called from 8
- method-call BisonParser\Syntax\RuleParser::item() packages/bison-parser/src/Syntax/RuleParser.php:128
- method-call BisonParser\Syntax\RuleParser::symbolToken() packages/bison-parser/src/Syntax/RuleParser.php:214
- method-call BisonParser\Syntax\SymbolListParser::entries() packages/bison-parser/src/Syntax/SymbolListParser.php:106
- method-call BisonParser\Syntax\SymbolListParser::entries() packages/bison-parser/src/Syntax/SymbolListParser.php:111
- method-call BisonParser\Syntax\SymbolListParser::symbols() packages/bison-parser/src/Syntax/SymbolListParser.php:165
- method-call BisonParser\Syntax\SymbolListParser::symbols() packages/bison-parser/src/Syntax/SymbolListParser.php:166
- method-call BisonParser\Syntax\SymbolListParser::targets() packages/bison-parser/src/Syntax/SymbolListParser.php:194
- method-call BisonParser\Syntax\SymbolListParser::passesLine() packages/bison-parser/src/Syntax/SymbolListParser.php:222
Calls 4
- method-call Token::is() line 239
- class-const TokenKind::Identifier() line 239
- class-const TokenKind::CharLiteral() line 239
- class-const TokenKind::String() line 239
Turns a symbol token into a symbol.
Parameters
$token | Token | An identifier, a character literal or a string token |
Returns
Symbol The symbolThrows
SyntaxException When the token is none of theseTest cases 2
Called from 6
- method-call BisonParser\Syntax\RuleParser::parse() packages/bison-parser/src/Syntax/RuleParser.php:68
- method-call BisonParser\Syntax\RuleParser::item() packages/bison-parser/src/Syntax/RuleParser.php:131
- method-call BisonParser\Syntax\RuleParser::modifier() packages/bison-parser/src/Syntax/RuleParser.php:195
- method-call BisonParser\Syntax\SymbolListParser::entry() packages/bison-parser/src/Syntax/SymbolListParser.php:138
- method-call BisonParser\Syntax\SymbolListParser::symbols() packages/bison-parser/src/Syntax/SymbolListParser.php:167
- method-call BisonParser\Syntax\SymbolListParser::targets() packages/bison-parser/src/Syntax/SymbolListParser.php:195
Calls 5
- method-call SymbolListParser::kind() line 253
- static-call SyntaxException::unexpected() line 253
- method-call Token::describe() line 253
- new Symbol line 255
- class-const SymbolKind::Identifier() line 255
public function kind(Token $token): SymbolKind|nullTells which kind of symbol a token denotes.
Parameters
$token | Token | Any token |
Returns
SymbolKind|null The kind, or null when the token denotes no symbolTest cases 1
Called from 2
Calls 8
- method-call Token::is() line 267
- class-const TokenKind::Identifier() line 267
- class-const TokenKind::IdentifierColon() line 267
- class-const SymbolKind::Identifier() line 268
- class-const TokenKind::CharLiteral() line 270
- class-const SymbolKind::CharLiteral() line 271
- class-const TokenKind::String() line 274
- class-const SymbolKind::String() line 274
public function describe(list<SymbolKind> $kinds): stringWords an error message with the kinds of symbol that were expected.
Parameters
$kinds | list<SymbolKind> | The kinds, at least one |
Returns
string For instance "an identifier or a character literal"Test cases 1
Called from 1
Calls 7
- class-const SymbolKind::Identifier() line 286
- class-const SymbolKind::CharLiteral() line 286
- class-const SymbolKind::String() line 286
- function-call
array_mapline 287 - function-call
countline 288 - function-call
implodeline 292 - function-call
array_sliceline 292
Test cases 30§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Dedicated tests 24
SymbolListParserTest::testDescribecallsSymbolListParserTest::testEntriescallsSymbolListParserTest::testEntriesPassOverALineBetweenEntriescallsSymbolListParserTest::testEntriesRejectASymbolOfAnotherKindcallsSymbolListParserTest::testEntriesRejectsAnEmptyListcallsSymbolListParserTest::testEntriesRejectsATagWithoutASymbolcallsSymbolListParserTest::testEntrycallsSymbolListParserTest::testKindcallsSymbolListParserTest::testNtermDeclarationscallsSymbolListParserTest::testNtermDeclarationsLeaveANumberUnreadcallsSymbolListParserTest::testNtermDeclarationsRejectACharacterLiteralcallsSymbolListParserTest::testNtermDeclarationsRejectAStringAliascallsSymbolListParserTest::testPassesLinecallsSymbolListParserTest::testPrecedenceDeclarationscallsSymbolListParserTest::testStartsSymbolcallsSymbolListParserTest::testSymbolcallsSymbolListParserTest::testSymbolRejectsAnotherTokencallsSymbolListParserTest::testSymbolscallsSymbolListParserTest::testSymbolsRejectsAnEmptyListcallsSymbolListParserTest::testTargetscallsSymbolListParserTest::testTargetsRejectsAnEmptyListcallsSymbolListParserTest::testTokenDeclarationscallsSymbolListParserTest::testTokenDeclarationsRejectAStringStartingAnEntrycallsSymbolListParserTest::testTypeDeclarationscalls
Other tests reaching this symbol 6
BisonGrammarCompilerTestcallsBisonGrammarReaderTestcallsParserTestcallsDeclarationParserTestcallsGrammarParserTestcallsRuleParserTestcalls
Relations§
Instantiated in 2
Method calls 11
- method-call BisonParser\Syntax\DeclarationParser::directive() packages/bison-parser/src/Syntax/DeclarationParser.php:127
- method-call BisonParser\Syntax\DeclarationParser::directive() packages/bison-parser/src/Syntax/DeclarationParser.php:128
- method-call BisonParser\Syntax\DeclarationParser::directive() packages/bison-parser/src/Syntax/DeclarationParser.php:130
- method-call BisonParser\Syntax\DeclarationParser::directive() packages/bison-parser/src/Syntax/DeclarationParser.php:131
- method-call BisonParser\Syntax\DeclarationParser::directive() packages/bison-parser/src/Syntax/DeclarationParser.php:132
- method-call BisonParser\Syntax\DeclarationParser::directive() packages/bison-parser/src/Syntax/DeclarationParser.php:133
- method-call BisonParser\Syntax\RuleParser::parse() packages/bison-parser/src/Syntax/RuleParser.php:68
- method-call BisonParser\Syntax\RuleParser::item() packages/bison-parser/src/Syntax/RuleParser.php:128
- method-call BisonParser\Syntax\RuleParser::item() packages/bison-parser/src/Syntax/RuleParser.php:131
- method-call BisonParser\Syntax\RuleParser::modifier() packages/bison-parser/src/Syntax/RuleParser.php:195
- method-call BisonParser\Syntax\RuleParser::symbolToken() packages/bison-parser/src/Syntax/RuleParser.php:214