99 * satisfy in order to be supported by this parser (e.g., no left recursion).
1010 */
1111class WP_Parser {
12- private $ grammar ;
13- private $ tokens ;
14- private $ position ;
15-
16- /**
17- * The current AST.
18- *
19- * @var WP_Parser_Node|null
20- */
21- private $ current_ast ;
12+ protected $ grammar ;
13+ protected $ tokens ;
14+ protected $ position ;
2215
2316 public function __construct ( WP_Parser_Grammar $ grammar , array $ tokens ) {
2417 $ this ->grammar = $ grammar ;
@@ -33,37 +26,6 @@ public function parse() {
3326 return false === $ ast ? null : $ ast ;
3427 }
3528
36- /**
37- * Parse the next AST from the input tokens.
38- *
39- * This method reads tokens from the input until an AST is successfully parsed.
40- * It starts from "$this->tokens[ $this->position ]", advances the number of
41- * tokens read, and returns a boolean indicating whether an AST was successfully
42- * parsed. When the end of the input is reached or a query could not be parsed,
43- * the method returns false.
44- *
45- * @return bool Whether an AST was successfully parsed.
46- */
47- public function next_ast (): bool {
48- if ( $ this ->position >= count ( $ this ->tokens ) ) {
49- return false ;
50- }
51- $ this ->current_ast = $ this ->parse ();
52- return true ;
53- }
54-
55- /**
56- * Get the current AST.
57- *
58- * When no AST has been parsed yet, the parsing failed, or the end of the
59- * input was reached, this method returns null.
60- *
61- * @return WP_Parser_Node|null The current AST, or null if no AST was parsed.
62- */
63- public function get_ast (): ?WP_Parser_Node {
64- return $ this ->current_ast ;
65- }
66-
6729 private function parse_recursive ( $ rule_id ) {
6830 $ is_terminal = $ rule_id <= $ this ->grammar ->highest_terminal_id ;
6931 if ( $ is_terminal ) {
0 commit comments