@@ -22,14 +22,15 @@ public function __construct( WP_Parser_Grammar $grammar, array $tokens ) {
2222 public function parse () {
2323 // @TODO: Make the starting rule lookup non-grammar-specific.
2424 $ query_rule_id = $ this ->grammar ->get_rule_id ( 'query ' );
25- return $ this ->parse_recursive ( $ query_rule_id );
25+ $ ast = $ this ->parse_recursive ( $ query_rule_id );
26+ return false === $ ast ? null : $ ast ;
2627 }
2728
2829 private function parse_recursive ( $ rule_id ) {
2930 $ is_terminal = $ rule_id <= $ this ->grammar ->highest_terminal_id ;
3031 if ( $ is_terminal ) {
3132 if ( $ this ->position >= count ( $ this ->tokens ) ) {
32- return null ;
33+ return false ;
3334 }
3435
3536 if ( WP_Parser_Grammar::EMPTY_RULE_ID === $ rule_id ) {
@@ -40,12 +41,12 @@ private function parse_recursive( $rule_id ) {
4041 ++$ this ->position ;
4142 return $ this ->tokens [ $ this ->position - 1 ];
4243 }
43- return null ;
44+ return false ;
4445 }
4546
4647 $ branches = $ this ->grammar ->rules [ $ rule_id ];
4748 if ( ! count ( $ branches ) ) {
48- return null ;
49+ return false ;
4950 }
5051
5152 // Bale out from processing the current branch if none of its rules can
@@ -56,7 +57,7 @@ private function parse_recursive( $rule_id ) {
5657 ! isset ( $ this ->grammar ->lookahead_is_match_possible [ $ rule_id ][ $ token_id ] ) &&
5758 ! isset ( $ this ->grammar ->lookahead_is_match_possible [ $ rule_id ][ WP_Parser_Grammar::EMPTY_RULE_ID ] )
5859 ) {
59- return null ;
60+ return false ;
6061 }
6162 }
6263
@@ -68,7 +69,7 @@ private function parse_recursive( $rule_id ) {
6869 $ branch_matches = true ;
6970 foreach ( $ branch as $ subrule_id ) {
7071 $ subnode = $ this ->parse_recursive ( $ subrule_id );
71- if ( null === $ subnode ) {
72+ if ( false === $ subnode ) {
7273 $ branch_matches = false ;
7374 break ;
7475 } elseif ( true === $ subnode ) {
@@ -111,7 +112,7 @@ private function parse_recursive( $rule_id ) {
111112
112113 if ( ! $ branch_matches ) {
113114 $ this ->position = $ starting_position ;
114- return null ;
115+ return false ;
115116 }
116117
117118 if ( 0 === count ( $ node ->children ) ) {
0 commit comments