11<?php
22
3- class WP_Parser_Tree {
3+ /**
4+ * A node in parse tree.
5+ *
6+ * This class represents a node in the parse tree that is produced by WP_Parser.
7+ * A node corresponds to the related grammar rule that was matched by the parser.
8+ * Each node can contain children, consisting of other nodes and grammar tokens.
9+ * In this way, a parser node constitutes a recursive structure that represents
10+ * a parse (sub)tree at each level of the full grammar tree.
11+ */
12+ class WP_Parser_Node {
13+ /**
14+ * @TODO: Review and document these properties and their visibility.
15+ */
416 public $ rule_id ;
517 public $ rule_name ;
618 public $ children = array ();
@@ -20,7 +32,7 @@ public function append_child( $node ) {
2032 *
2133 * What are rule fragments?
2234 *
23- * When we initially parse the BNF grammar file, it has compound rules such
35+ * When we initially parse the grammar file, it has compound rules such
2436 * as this one:
2537 *
2638 * query ::= EOF | ((simpleStatement | beginWork) ((SEMICOLON_SYMBOL EOF?) | EOF))
@@ -35,7 +47,7 @@ public function append_child( $node ) {
3547 * %%query02 ::= SEMICOLON_SYMBOL EOF_zero_or_one | EOF
3648 * EOF_zero_or_one ::= EOF | ε
3749 *
38- * This factorization happens in 1-ebnf-to-json.js .
50+ * This factorization happens in "convert-grammar.php" .
3951 *
4052 * "Fragments" are intermediate artifacts whose names are not in the original grammar.
4153 * They are extremely useful for the parser, but the API consumer should never have to
@@ -92,7 +104,7 @@ public function merge_fragment( $node ) {
92104
93105 public function has_child ( $ rule_name ) {
94106 foreach ( $ this ->children as $ child ) {
95- if ( ( $ child instanceof WP_Parser_Tree && $ child ->rule_name === $ rule_name ) ) {
107+ if ( ( $ child instanceof WP_Parser_Node && $ child ->rule_name === $ rule_name ) ) {
96108 return true ;
97109 }
98110 }
@@ -125,7 +137,7 @@ public function get_token( $token_id = null ) {
125137
126138 public function get_child ( $ rule_name = null ) {
127139 foreach ( $ this ->children as $ child ) {
128- if ( $ child instanceof WP_Parser_Tree && (
140+ if ( $ child instanceof WP_Parser_Node && (
129141 $ child ->rule_name === $ rule_name ||
130142 null === $ rule_name
131143 ) ) {
@@ -160,7 +172,7 @@ public function get_descendants( $rule_name ) {
160172 public function get_children ( $ rule_name = null ) {
161173 $ matches = array ();
162174 foreach ( $ this ->children as $ child ) {
163- if ( $ child instanceof WP_Parser_Tree && (
175+ if ( $ child instanceof WP_Parser_Node && (
164176 null === $ rule_name ||
165177 $ child ->rule_name === $ rule_name
166178 ) ) {
0 commit comments