classDeclarationParser
final class DeclarationParser
Restricted visibility: declared "@visibility root". Code outside that scope must not name this declaration.
Reads one declaration, following the prologue_declaration and grammar_declaration rules of parse-gram.y.
Methods§
public function __construct(private SymbolListParser $symbols = new \BisonParser\Syntax\SymbolListParser())Parameters
$symbols | SymbolListParser | Reads the symbol lists of declarations |
Calls 1
public function starts(Token $token): boolReports whether a token begins a declaration.
Parameters
$token | Token | Token to look at |
Returns
bool True for a prologue or a directive that is not a rule modifierTest cases 1
Called from 2
Calls 5
- method-call Token::is() line 54
- class-const TokenKind::Prologue() line 54
- class-const TokenKind::Line() line 55
- class-const TokenKind::Directive() line 56
- function-call
in_arrayline 56
public function parse(TokenStream $tokens): DeclarationReads the declaration that begins at the current token.
Parameters
$tokens | TokenStream | Tokens positioned on a prologue or directive |
Returns
Declaration The declarationThrows
SyntaxException When the directive lacks its argument or is not a declarationTest cases 3
Called from 3
- method-call BisonParser\Syntax\GrammarParser::parse() packages/bison-parser/src/Syntax/GrammarParser.php:50
- method-call BisonParser\Syntax\GrammarParser::parse() packages/bison-parser/src/Syntax/GrammarParser.php:61
- method-call BisonParser\Syntax\GrammarParser::parse() packages/bison-parser/src/Syntax/GrammarParser.php:63
Calls 8
- method-call TokenStream::next() line 70
- class-const TokenKind::Prologue() line 71
- new Prologue line 72
- class-const TokenKind::Line() line 74
- method-call DeclarationParser::line() line 75
- class-const TokenKind::Directive() line 77
- static-call SyntaxException::unexpected() line 78
- method-call DeclarationParser::directive() line 81
public function directive(Token $token, TokenStream $tokens): DeclarationReads the arguments of a directive whose name token was just consumed.
Parameters
$token | Token | The directive token |
$tokens | TokenStream | Tokens positioned after the directive |
Returns
Declaration The declarationThrows
SyntaxException When the directive lacks its argument or is not a declarationTest cases 5
DeclarationParserTest::testDirectivecallsDeclarationParserTest::testDirectiveReadsNtermAsNonterminalscallsDeclarationParserTest::testDirectiveRejectsAnOptionWithoutItsStringcallsDeclarationParserTest::testDirectiveRejectsANtermThatIsNotAnIdentifiercallsDeclarationParserTest::testDirectiveRejectsARuleModifiercalls
Called from 1
Calls 34
- function-call
in_arrayline 112 - class-const Directives::FLAGS() line 112
- new Flag line 113
- class-const Directives::OPTIONS() line 115
- method-call TokenStream::accept() line 116
- class-const TokenKind::String() line 116
- method-call TokenStream::expect() line 116
- new Option line 118
- method-call DeclarationParser::define() line 122
- new Expect line 123
- class-const TokenKind::Integer() line 123
- new InitialAction line 124
- class-const TokenKind::Code() line 124
- new Param line 125
- static-call ParamKind::from() line 125
- method-call DeclarationParser::codes() line 125
- new UnionDeclaration line 126
- class-const TokenKind::Identifier() line 126
- new Start line 127
- method-call SymbolListParser::symbols() line 127
- new CodeProps line 128
- method-call SymbolListParser::targets() line 128
- new Code line 129
- new SymbolDeclaration line 130
- class-const SymbolClass::Token() line 130
- method-call SymbolListParser::tokenDeclarations() line 130
- class-const SymbolClass::Nonterminal() line 131
- method-call SymbolListParser::ntermDeclarations() line 131
- class-const SymbolClass::Type() line 132
- method-call SymbolListParser::typeDeclarations() line 132
- new PrecedenceDeclaration line 133
- static-call Associativity::from() line 133
- method-call SymbolListParser::precedenceDeclarations() line 133
- static-call SyntaxException::unexpected() line 134
public function define(TokenStream $tokens, Location $at): DefineReads the variable and optional value of a %define.
Parameters
$tokens | TokenStream | Tokens positioned after the directive |
$at | Location | Where the directive is written |
Returns
Define The declarationThrows
SyntaxException When no variable followsTest cases 2
Called from 1
Calls 12
- method-call TokenStream::expect() line 150
- class-const TokenKind::Identifier() line 150
- method-call TokenStream::accept() line 151
- class-const TokenKind::Equal() line 151
- method-call TokenStream::is() line 153
- class-const DefineForm::Keyword() line 154
- class-const TokenKind::String() line 155
- class-const DefineForm::String() line 156
- class-const TokenKind::Code() line 157
- class-const DefineForm::Code() line 158
- new Define line 161
- method-call TokenStream::next() line 164
public function codes(TokenStream $tokens, string $name): list<string>Reads the one or more braced arguments of a %param directive.
Parameters
$tokens | TokenStream | Tokens positioned after the directive |
$name | string | Directive name, for the error |
Returns
list<string> Each argument's code without its bracesThrows
SyntaxException When no braced argument followsTest cases 2
Called from 1
Calls 3
- method-call TokenStream::expect() line 179
- class-const TokenKind::Code() line 179
- method-call TokenStream::accept() line 180
Private surface 1§
Implementation details, listed for orientation only.
private SymbolListParser $symbols = new \BisonParser\Syntax\SymbolListParser()Test cases 19§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Dedicated tests 14
DeclarationParserTest::testCodescallsDeclarationParserTest::testCodesRejectsAMissingBlockcallsDeclarationParserTest::testDefinecallsDeclarationParserTest::testDefineRejectsAMissingVariablecallsDeclarationParserTest::testDirectivecallsDeclarationParserTest::testDirectiveReadsNtermAsNonterminalscallsDeclarationParserTest::testDirectiveRejectsAnOptionWithoutItsStringcallsDeclarationParserTest::testDirectiveRejectsANtermThatIsNotAnIdentifiercallsDeclarationParserTest::testDirectiveRejectsARuleModifiercallsDeclarationParserTest::testLinecallsDeclarationParserTest::testParsecallsDeclarationParserTest::testParseReadsALineDirectivecallsDeclarationParserTest::testParseRejectsANonDeclarationcallsDeclarationParserTest::testStartscalls
Other tests reaching this symbol 5
BisonGrammarCompilerTestcallsBisonGrammarReaderTestcallsParserTestcallsGrammarParserTestcallsRuleParserTestcalls
Relations§
Instantiated in 2
Method calls 6
- method-call BisonParser\Syntax\GrammarParser::parse() packages/bison-parser/src/Syntax/GrammarParser.php:47
- method-call BisonParser\Syntax\GrammarParser::parse() packages/bison-parser/src/Syntax/GrammarParser.php:50
- method-call BisonParser\Syntax\GrammarParser::parse() packages/bison-parser/src/Syntax/GrammarParser.php:61
- method-call BisonParser\Syntax\GrammarParser::parse() packages/bison-parser/src/Syntax/GrammarParser.php:62
- method-call BisonParser\Syntax\GrammarParser::parse() packages/bison-parser/src/Syntax/GrammarParser.php:63
- method-call BisonParser\Syntax\RuleParser::item() packages/bison-parser/src/Syntax/RuleParser.php:144