@@ -15,17 +15,14 @@ class WP_Parser_Node {
1515 */
1616 public $ rule_id ;
1717 public $ rule_name ;
18- private $ children = array ();
19- private $ native_ast = null ;
20- private $ native_node_index = null ;
18+ private $ children = array ();
2119
2220 public function __construct ( $ rule_id , $ rule_name ) {
2321 $ this ->rule_id = $ rule_id ;
2422 $ this ->rule_name = $ rule_name ;
2523 }
2624
2725 public function append_child ( $ node ) {
28- $ this ->materialize_native_children ();
2926 $ this ->children [] = $ node ;
3027 }
3128
@@ -102,8 +99,6 @@ public function append_child( $node ) {
10299 * ]
103100 */
104101 public function merge_fragment ( $ node ) {
105- $ this ->materialize_native_children ();
106- $ node ->materialize_native_children ();
107102 $ this ->children = array_merge ( $ this ->children , $ node ->children );
108103 }
109104
@@ -113,9 +108,6 @@ public function merge_fragment( $node ) {
113108 * @return bool True if this node has any child nodes or tokens, false otherwise.
114109 */
115110 public function has_child (): bool {
116- if ( $ this ->has_native_ast () ) {
117- return wp_sqlite_mysql_native_ast_has_child ( $ this ->native_ast , $ this ->native_node_index );
118- }
119111 return count ( $ this ->children ) > 0 ;
120112 }
121113
@@ -126,9 +118,6 @@ public function has_child(): bool {
126118 * @return bool True if any child nodes are found, false otherwise.
127119 */
128120 public function has_child_node ( ?string $ rule_name = null ): bool {
129- if ( $ this ->has_native_ast () ) {
130- return wp_sqlite_mysql_native_ast_has_child_node ( $ this ->native_ast , $ this ->native_node_index , $ rule_name );
131- }
132121 foreach ( $ this ->children as $ child ) {
133122 if (
134123 $ child instanceof WP_Parser_Node
@@ -147,9 +136,6 @@ public function has_child_node( ?string $rule_name = null ): bool {
147136 * @return bool True if any child tokens are found, false otherwise.
148137 */
149138 public function has_child_token ( ?int $ token_id = null ): bool {
150- if ( $ this ->has_native_ast () ) {
151- return wp_sqlite_mysql_native_ast_has_child_token ( $ this ->native_ast , $ this ->native_node_index , $ token_id );
152- }
153139 foreach ( $ this ->children as $ child ) {
154140 if (
155141 $ child instanceof WP_Parser_Token
@@ -168,9 +154,6 @@ public function has_child_token( ?int $token_id = null ): bool {
168154 * null when no children are found.
169155 */
170156 public function get_first_child () {
171- if ( $ this ->has_native_ast () ) {
172- return wp_sqlite_mysql_native_ast_get_first_child ( $ this ->native_ast , $ this ->native_node_index );
173- }
174157 return $ this ->children [0 ] ?? null ;
175158 }
176159
@@ -181,9 +164,6 @@ public function get_first_child() {
181164 * @return WP_Parser_Node|null The first matching child node; null when no children are found.
182165 */
183166 public function get_first_child_node ( ?string $ rule_name = null ): ?WP_Parser_Node {
184- if ( $ this ->has_native_ast () ) {
185- return wp_sqlite_mysql_native_ast_get_first_child_node ( $ this ->native_ast , $ this ->native_node_index , $ rule_name );
186- }
187167 foreach ( $ this ->children as $ child ) {
188168 if (
189169 $ child instanceof WP_Parser_Node
@@ -202,9 +182,6 @@ public function get_first_child_node( ?string $rule_name = null ): ?WP_Parser_No
202182 * @return WP_Parser_Token|null The first matching child token; null when no children are found.
203183 */
204184 public function get_first_child_token ( ?int $ token_id = null ): ?WP_Parser_Token {
205- if ( $ this ->has_native_ast () ) {
206- return wp_sqlite_mysql_native_ast_get_first_child_token ( $ this ->native_ast , $ this ->native_node_index , $ token_id );
207- }
208185 foreach ( $ this ->children as $ child ) {
209186 if (
210187 $ child instanceof WP_Parser_Token
@@ -226,9 +203,6 @@ public function get_first_child_token( ?int $token_id = null ): ?WP_Parser_Token
226203 * @return WP_Parser_Node|null The first matching descendant node; null when no descendants are found.
227204 */
228205 public function get_first_descendant_node ( ?string $ rule_name = null ): ?WP_Parser_Node {
229- if ( $ this ->has_native_ast () ) {
230- return wp_sqlite_mysql_native_ast_get_first_descendant_node ( $ this ->native_ast , $ this ->native_node_index , $ rule_name );
231- }
232206 for ( $ i = 0 ; $ i < count ( $ this ->children ); $ i ++ ) {
233207 $ child = $ this ->children [ $ i ];
234208 if ( ! $ child instanceof WP_Parser_Node ) {
@@ -255,9 +229,6 @@ public function get_first_descendant_node( ?string $rule_name = null ): ?WP_Pars
255229 * @return WP_Parser_Token|null The first matching descendant token; null when no descendants are found.
256230 */
257231 public function get_first_descendant_token ( ?int $ token_id = null ): ?WP_Parser_Token {
258- if ( $ this ->has_native_ast () ) {
259- return wp_sqlite_mysql_native_ast_get_first_descendant_token ( $ this ->native_ast , $ this ->native_node_index , $ token_id );
260- }
261232 for ( $ i = 0 ; $ i < count ( $ this ->children ); $ i ++ ) {
262233 $ child = $ this ->children [ $ i ];
263234 if ( $ child instanceof WP_Parser_Token ) {
@@ -280,9 +251,6 @@ public function get_first_descendant_token( ?int $token_id = null ): ?WP_Parser_
280251 * @return array<WP_Parser_Node|WP_Parser_Token> An array of all child nodes and tokens of this node.
281252 */
282253 public function get_children (): array {
283- if ( $ this ->has_native_ast () ) {
284- return wp_sqlite_mysql_native_ast_get_children ( $ this ->native_ast , $ this ->native_node_index );
285- }
286254 return $ this ->children ;
287255 }
288256
@@ -293,9 +261,6 @@ public function get_children(): array {
293261 * @return WP_Parser_Node[] An array of all matching child nodes.
294262 */
295263 public function get_child_nodes ( ?string $ rule_name = null ): array {
296- if ( $ this ->has_native_ast () ) {
297- return wp_sqlite_mysql_native_ast_get_child_nodes ( $ this ->native_ast , $ this ->native_node_index , $ rule_name );
298- }
299264 $ nodes = array ();
300265 foreach ( $ this ->children as $ child ) {
301266 if (
@@ -315,9 +280,6 @@ public function get_child_nodes( ?string $rule_name = null ): array {
315280 * @return WP_Parser_Token[] An array of all matching child tokens.
316281 */
317282 public function get_child_tokens ( ?int $ token_id = null ): array {
318- if ( $ this ->has_native_ast () ) {
319- return wp_sqlite_mysql_native_ast_get_child_tokens ( $ this ->native_ast , $ this ->native_node_index , $ token_id );
320- }
321283 $ tokens = array ();
322284 foreach ( $ this ->children as $ child ) {
323285 if (
@@ -339,9 +301,6 @@ public function get_child_tokens( ?int $token_id = null ): array {
339301 * @return array<WP_Parser_Node|WP_Parser_Token> An array of all descendant nodes and tokens of this node.
340302 */
341303 public function get_descendants (): array {
342- if ( $ this ->has_native_ast () ) {
343- return wp_sqlite_mysql_native_ast_get_descendants ( $ this ->native_ast , $ this ->native_node_index );
344- }
345304 $ descendants = array ();
346305 foreach ( $ this ->children as $ child ) {
347306 if ( $ child instanceof WP_Parser_Node ) {
@@ -365,9 +324,6 @@ public function get_descendants(): array {
365324 * @return WP_Parser_Node[] An array of all matching descendant nodes.
366325 */
367326 public function get_descendant_nodes ( ?string $ rule_name = null ): array {
368- if ( $ this ->has_native_ast () ) {
369- return wp_sqlite_mysql_native_ast_get_descendant_nodes ( $ this ->native_ast , $ this ->native_node_index , $ rule_name );
370- }
371327 $ nodes = array ();
372328 foreach ( $ this ->children as $ child ) {
373329 if ( ! $ child instanceof WP_Parser_Node ) {
@@ -392,9 +348,6 @@ public function get_descendant_nodes( ?string $rule_name = null ): array {
392348 * @return WP_Parser_Token[] An array of all matching descendant tokens.
393349 */
394350 public function get_descendant_tokens ( ?int $ token_id = null ): array {
395- if ( $ this ->has_native_ast () ) {
396- return wp_sqlite_mysql_native_ast_get_descendant_tokens ( $ this ->native_ast , $ this ->native_node_index , $ token_id );
397- }
398351 $ tokens = array ();
399352 foreach ( $ this ->children as $ child ) {
400353 if ( $ child instanceof WP_Parser_Token ) {
@@ -414,9 +367,6 @@ public function get_descendant_tokens( ?int $token_id = null ): array {
414367 * @return int The byte offset in the input string where this node begins.
415368 */
416369 public function get_start (): int {
417- if ( $ this ->has_native_ast () ) {
418- return wp_sqlite_mysql_native_ast_get_start ( $ this ->native_ast , $ this ->native_node_index );
419- }
420370 return $ this ->get_first_descendant_token ()->start ;
421371 }
422372
@@ -426,26 +376,9 @@ public function get_start(): int {
426376 * @return int The byte length of this node in the input string.
427377 */
428378 public function get_length (): int {
429- if ( $ this ->has_native_ast () ) {
430- return wp_sqlite_mysql_native_ast_get_length ( $ this ->native_ast , $ this ->native_node_index );
431- }
432379 $ tokens = $ this ->get_descendant_tokens ();
433380 $ first_token = $ tokens [0 ];
434381 $ last_token = $ tokens [ count ( $ tokens ) - 1 ];
435382 return $ last_token ->start + $ last_token ->length - $ first_token ->start ;
436383 }
437-
438- private function has_native_ast (): bool {
439- return null !== $ this ->native_ast ;
440- }
441-
442- private function materialize_native_children (): void {
443- if ( ! $ this ->has_native_ast () ) {
444- return ;
445- }
446-
447- $ this ->children = wp_sqlite_mysql_native_ast_get_children ( $ this ->native_ast , $ this ->native_node_index );
448- $ this ->native_ast = null ;
449- $ this ->native_node_index = null ;
450- }
451384}
0 commit comments