classDeclarationReader
final class DeclarationReader
Restricted visibility: declared "@visibility root". Code outside that scope must not name this declaration.
Reads a declaration after its % sign, as Lemon's declaration states do.
Methods§
public function __construct(private SymbolListReader $lists = new \LemonParser\Syntax\SymbolListReader())Parameters
$lists | SymbolListReader | Reads lists of terminals ended by a period |
Calls 1
public function read(TokenStream $tokens, SymbolRegistry $registry, Location $at): DeclarationReads the declaration whose % has been taken.
Parameters
$tokens | TokenStream | The rest |
$registry | SymbolRegistry | Symbols seen so far |
$at | Location | Where the `%` is |
Returns
Declaration The declarationThrows
SyntaxException Where Lemon reports an errorTest cases 3
Called from 1
Calls 17
- method-call TokenStream::next() line 52
- new SyntaxException line 54
- static-call DirectiveKeyword::tryFrom() line 56
- method-call DeclarationReader::argument() line 58
- new Directive line 60
- static-call Associativity::tryFrom() line 62
- new PrecedenceDeclaration line 64
- method-call SymbolListReader::ranked() line 64
- method-call DeclarationReader::readDestructor() line 68
- method-call DeclarationReader::readType() line 69
- new Fallback line 70
- method-call SymbolListReader::fallbacks() line 70
- new TokenDeclaration line 71
- method-call SymbolListReader::tokens() line 71
- new Wildcard line 72
- method-call SymbolListReader::wildcard() line 72
- method-call DeclarationReader::readTokenClass() line 73
public function argument(TokenStream $tokens, Token $keyword): array{string, ArgumentForm}Reads the one argument of a keyword: braced code, a string or a word.
Parameters
$tokens | TokenStream | The rest |
$keyword | Token | The keyword, for messages |
Returns
array{string, ArgumentForm} The argument without delimiters and how it was writtenThrows
SyntaxException When what follows is none of the threeTest cases 2
Called from 3
- method-call LemonParser\Syntax\DeclarationReader::read() packages/lemon-parser/src/Syntax/DeclarationReader.php:58
- method-call LemonParser\Syntax\DeclarationReader::readDestructor() packages/lemon-parser/src/Syntax/DeclarationReader.php:122
- method-call LemonParser\Syntax\DeclarationReader::readType() packages/lemon-parser/src/Syntax/DeclarationReader.php:145
Calls 12
- method-call TokenStream::next() line 90
- class-const TokenKind::Code() line 92
- class-const ArgumentForm::Code() line 92
- class-const TokenKind::String() line 93
- class-const ArgumentForm::String() line 93
- class-const TokenKind::Word() line 94
- class-const ArgumentForm::Word() line 94
- class-const TokenKind::Arrow() line 95
- class-const TokenKind::Compound() line 95
- class-const TokenKind::Punctuation() line 95
- class-const TokenKind::End() line 95
- new SyntaxException line 98
public function readDestructor(
TokenStream $tokens,
SymbolRegistry $registry,
Location $at,
): DestructorReads %destructor symbol argument.
Parameters
$tokens | TokenStream | The rest |
$registry | SymbolRegistry | Symbols seen so far |
$at | Location | Where the `%` is |
Returns
Destructor The declarationThrows
SyntaxException When no symbol followsTest cases 2
Called from 1
Calls 6
- method-call TokenStream::next() line 117
- new SyntaxException line 119
- method-call SymbolRegistry::see() line 121
- method-call DeclarationReader::argument() line 122
- new Destructor line 124
- new Symbol line 124
public function readType(
TokenStream $tokens,
SymbolRegistry $registry,
Location $at,
): TypeDeclarationReads %type symbol argument.
Parameters
$tokens | TokenStream | The rest |
$registry | SymbolRegistry | Symbols seen so far |
$at | Location | Where the `%` is |
Returns
TypeDeclaration The declarationThrows
SyntaxException When no symbol follows or it is already typedTest cases 3
Called from 1
Calls 6
- method-call TokenStream::next() line 140
- new SyntaxException line 142
- method-call SymbolRegistry::type() line 144
- method-call DeclarationReader::argument() line 145
- new TypeDeclaration line 147
- new Symbol line 147
public function readTokenClass(
TokenStream $tokens,
SymbolRegistry $registry,
Location $at,
): TokenClassReads %token_class name TOKEN|TOKEN... ..
Parameters
$tokens | TokenStream | The rest |
$registry | SymbolRegistry | Symbols seen so far |
$at | Location | Where the `%` is |
Returns
TokenClass The declarationThrows
SyntaxException When the name is not a fresh nonterminal nameTest cases 3
Called from 1
Calls 7
- method-call TokenStream::next() line 163
- new SyntaxException line 165
- method-call SymbolRegistry::isKnown() line 167
- method-call SymbolRegistry::see() line 170
- new TokenClass line 172
- new Symbol line 172
- method-call SymbolListReader::classTokens() line 172
Private surface 1§
Implementation details, listed for orientation only.
private SymbolListReader $lists = new \LemonParser\Syntax\SymbolListReader()Test cases 17§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Dedicated tests 13
DeclarationReaderTest::testArgumentcallsDeclarationReaderTest::testArgumentRejectsPunctuationcallsDeclarationReaderTest::testReadcallsDeclarationReaderTest::testReadDestructorcallsDeclarationReaderTest::testReadDestructorRejectsAMissingSymbolcallsDeclarationReaderTest::testReadRejectsAKeywordThatIsNotAWordcallsDeclarationReaderTest::testReadRejectsAnUnknownKeywordcallsDeclarationReaderTest::testReadTokenClasscallsDeclarationReaderTest::testReadTokenClassRejectsAKnownNamecallsDeclarationReaderTest::testReadTokenClassRejectsATerminalNamecallsDeclarationReaderTest::testReadTypecallsDeclarationReaderTest::testReadTypeRejectsAMissingSymbolcallsDeclarationReaderTest::testReadTypeRejectsASecondTypecalls
Other tests reaching this symbol 4
LemonGrammarCompilerTestcallsLemonGrammarReaderTestcallsParserTestcallsGrammarReaderTestcalls