Example #1
0
 /**
  * @inheritdoc
  * @return AbstractQueryNode
  */
 public function parse(TokenStream $tokenStream)
 {
     $operator = null;
     $queries = [];
     $tokenStream->expect(Token::T_OPEN_PARENTHESIS);
     do {
         $queries[] = $this->conditionTokenParser->parse($tokenStream);
         if ($tokenStream->nextIf(Token::T_AMPERSAND)) {
             if ($operator === null) {
                 $operator = Token::T_AMPERSAND;
             } elseif ($operator !== Token::T_AMPERSAND) {
                 throw new SyntaxErrorException('Cannot mix "&" and "|" within a group');
             }
         } elseif ($tokenStream->nextIf(Token::T_VERTICAL_BAR)) {
             if ($operator === null) {
                 $operator = Token::T_VERTICAL_BAR;
             } elseif ($operator !== Token::T_VERTICAL_BAR) {
                 throw new SyntaxErrorException('Cannot mix "&" and "|" within a group');
             }
         } else {
             break;
         }
     } while (true);
     $tokenStream->expect(Token::T_CLOSE_PARENTHESIS);
     if ($operator === Token::T_VERTICAL_BAR) {
         return new OrNode($queries);
     } elseif ($operator === Token::T_AMPERSAND) {
         return new AndNode($queries);
     } else {
         return $queries[0];
     }
 }
Example #2
0
 /**
  * @param TokenParserInterface $tokenParser
  * @return $this
  */
 public function addTokenParser(TokenParserInterface $tokenParser)
 {
     if ($this->getParser() !== null) {
         $tokenParser->setParser($this->getParser());
     }
     $this->tokenParsers[] = $tokenParser;
     return $this;
 }
 /**
  * @inheritdoc
  */
 public function parse(TokenStream $tokenStream)
 {
     $tokenStream->expect(Token::T_OPERATOR, $this->getOperatorName());
     $tokenStream->expect(Token::T_OPEN_PARENTHESIS);
     $queries = [];
     do {
         $queries[] = $this->conditionTokenParser->parse($tokenStream);
         if (!$tokenStream->nextIf(Token::T_COMMA)) {
             break;
         }
     } while (true);
     $tokenStream->expect(Token::T_CLOSE_PARENTHESIS);
     return $this->createNode($queries);
 }