classLrParser
final class LrParser
Restricted visibility: declared "@visibility root". Code outside that scope must not name this declaration.
Drives a parse table over a token stream and builds the syntax tree.
This is the shift-reduce loop every LALR(1) parser runs. A shift pushes the token; a reduce pops the symbols of a rule and pushes a node for its nonterminal, unless the rule stands in for a mid-rule action, which leaves no node. Accepting yields the node of the grammar's start symbol, which takes over the trivia of the end marker the augmented start rule ends with, so the text after the last token of the stream belongs to the tree too.
Methods§
public function __construct(private ParseTable $table)Parameters
$table | ParseTable | Table to drive |
Parses a token stream.
Parameters
$tokens | list<Token> | Tokens ending with the end marker |
$source | string | The SQL text, for error positions |
Returns
Node The node of the start symbolThrows
SyntaxException When a token is not allowed where it standsTest cases 5
LrParserTest::testParseBuildsATreeNamedAfterTheRulescallsLrParserTest::testParseGivesTheTreeTheTextThatFollowsTheLastTokencallsLrParserTest::testParseLeavesMidRuleActionsOutOfTheTreecallsLrParserTest::testParseRejectsAnUnexpectedTokencallsLrParserTest::testParseSuppliesTheEndMarkerWhenTheStreamLacksItcalls
Called from 3
- method-call SqlParser\MySql\MySqlParser::parse() packages/sql-parser/src/MySql/MySqlParser.php:109
- method-call SqlParser\PostgreSql\PostgreSqlParser::parse() packages/sql-parser/src/PostgreSql/PostgreSqlParser.php:105
- method-call SqlParser\Sqlite\SqliteParser::parse() packages/sql-parser/src/Sqlite/SqliteParser.php:110
Calls 15
- new Token line 48
- function-call
strlenline 48 - function-call
countline 50 - method-call ParseTable::action() line 51
- class-const ActionCode::ERROR() line 52
- new SyntaxException line 53
- method-call LrParser::expected() line 53
- static-call ActionCode::isShift() line 55
- static-call ActionCode::rule() line 61
- function-call
array_valuesline 64 - function-call
array_filterline 64 - function-call
array_spliceline 64 - class-const ActionCode::ACCEPT() line 67
- function-call
array_popline 68 - new Node line 73
public function expected(int $state): list<string>Names the terminals a state accepts, for an error message.
Parameters
$state | int | State the parser was in |
Returns
list<string> Terminal namesTest cases 1
Called from 1
Calls 2
- function-call
array_mapline 90 - method-call ParseTable::expectedTerminals() line 90
Private surface 1§
Implementation details, listed for orientation only.
private ParseTable $tableTest cases 10§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Dedicated tests 6
LrParserTest::testExpectedcallsLrParserTest::testParseBuildsATreeNamedAfterTheRulescallsLrParserTest::testParseGivesTheTreeTheTextThatFollowsTheLastTokencallsLrParserTest::testParseLeavesMidRuleActionsOutOfTheTreecallsLrParserTest::testParseRejectsAnUnexpectedTokencallsLrParserTest::testParseSuppliesTheEndMarkerWhenTheStreamLacksItcalls
Other tests reaching this symbol 4
Relations§
Instantiated in 3
Method calls 3
- method-call SqlParser\MySql\MySqlParser::parse() packages/sql-parser/src/MySql/MySqlParser.php:109
- method-call SqlParser\PostgreSql\PostgreSqlParser::parse() packages/sql-parser/src/PostgreSql/PostgreSqlParser.php:105
- method-call SqlParser\Sqlite\SqliteParser::parse() packages/sql-parser/src/Sqlite/SqliteParser.php:110