|
1 | 1 | <?php |
2 | 2 |
|
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 | + */ |
4 | 16 | public $rule_id; |
5 | 17 | public $rule_name; |
6 | 18 | public $children = array(); |
@@ -92,7 +104,7 @@ public function merge_fragment( $node ) { |
92 | 104 |
|
93 | 105 | public function has_child( $rule_name ) { |
94 | 106 | 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 ) ) { |
96 | 108 | return true; |
97 | 109 | } |
98 | 110 | } |
@@ -125,7 +137,7 @@ public function get_token( $token_id = null ) { |
125 | 137 |
|
126 | 138 | public function get_child( $rule_name = null ) { |
127 | 139 | foreach ( $this->children as $child ) { |
128 | | - if ( $child instanceof WP_Parser_Tree && ( |
| 140 | + if ( $child instanceof WP_Parser_Node && ( |
129 | 141 | $child->rule_name === $rule_name || |
130 | 142 | null === $rule_name |
131 | 143 | ) ) { |
@@ -160,7 +172,7 @@ public function get_descendants( $rule_name ) { |
160 | 172 | public function get_children( $rule_name = null ) { |
161 | 173 | $matches = array(); |
162 | 174 | foreach ( $this->children as $child ) { |
163 | | - if ( $child instanceof WP_Parser_Tree && ( |
| 175 | + if ( $child instanceof WP_Parser_Node && ( |
164 | 176 | null === $rule_name || |
165 | 177 | $child->rule_name === $rule_name |
166 | 178 | ) ) { |
|
0 commit comments