| @@ 108-129 (lines=22) @@ | ||
| 105 | /** |
|
| 106 | * @return Ast\Term|Ast\Disjunction |
|
| 107 | */ |
|
| 108 | private function disjunction() |
|
| 109 | { |
|
| 110 | /** @var Ast\Term[] $terms */ |
|
| 111 | $terms = []; |
|
| 112 | $terms[] = $this->conjunction(); |
|
| 113 | ||
| 114 | if ($this->lexer->isNextToken(Tokens::T_SP)) { |
|
| 115 | $nextToken = $this->lexer->glimpse(); |
|
| 116 | if ($nextToken && $nextToken->is(Tokens::T_OR)) { |
|
| 117 | $this->match(Tokens::T_SP); |
|
| 118 | $this->match(Tokens::T_OR); |
|
| 119 | $this->match(Tokens::T_SP); |
|
| 120 | $terms[] = $this->conjunction(); |
|
| 121 | } |
|
| 122 | } |
|
| 123 | ||
| 124 | if (count($terms) == 1) { |
|
| 125 | return $terms[0]; |
|
| 126 | } |
|
| 127 | ||
| 128 | return new Ast\Disjunction($terms); |
|
| 129 | } |
|
| 130 | ||
| 131 | /** |
|
| 132 | * @return Ast\Conjunction|Ast\Factor |
|
| @@ 134-154 (lines=21) @@ | ||
| 131 | /** |
|
| 132 | * @return Ast\Conjunction|Ast\Factor |
|
| 133 | */ |
|
| 134 | private function conjunction() |
|
| 135 | { |
|
| 136 | $factors = []; |
|
| 137 | $factors[] = $this->factor(); |
|
| 138 | ||
| 139 | if ($this->lexer->isNextToken(Tokens::T_SP)) { |
|
| 140 | $nextToken = $this->lexer->glimpse(); |
|
| 141 | if ($nextToken && $nextToken->is(Tokens::T_AND)) { |
|
| 142 | $this->match(Tokens::T_SP); |
|
| 143 | $this->match(Tokens::T_AND); |
|
| 144 | $this->match(Tokens::T_SP); |
|
| 145 | $factors[] = $this->factor(); |
|
| 146 | } |
|
| 147 | } |
|
| 148 | ||
| 149 | if (count($factors) == 1) { |
|
| 150 | return $factors[0]; |
|
| 151 | } |
|
| 152 | ||
| 153 | return new Ast\Conjunction($factors); |
|
| 154 | } |
|
| 155 | ||
| 156 | /** |
|
| 157 | * @return Ast\Filter |
|