/**
  * @inheritdoc
  */
 public function parse(TokenStream $tokenStream)
 {
     $field = $tokenStream->expect(Token::T_STRING)->getValue();
     $tokenStream->expect(Token::T_OPERATOR, $this->getOperatorNames());
     $values = $this->getParser()->getExpressionParser()->parseArray($tokenStream);
     return $this->createNode($field, $values);
 }
 /**
  * @param \Xiag\Rql\Parser\TokenStream $tokenStream
  *
  * @return \AndreasGlaser\DoctrineRql\Extension\Xiag\Rql\Parser\Node\Query\AbstractNullOperatorNode
  * @author Andreas Glaser
  */
 public function parse(TokenStream $tokenStream)
 {
     $tokenStream->expect(Token::T_OPERATOR, $this->getOperatorName());
     $tokenStream->expect(Token::T_OPEN_PARENTHESIS);
     $field = $this->fieldNameParser->parse($tokenStream);
     $tokenStream->expect(Token::T_CLOSE_PARENTHESIS);
     return $this->createNode($field);
 }
Пример #3
0
 /**
  * @inheritdoc
  */
 public function parse(TokenStream $tokenStream)
 {
     if ($tokenStream->test(Token::T_GLOB)) {
         return new Glob($tokenStream->next()->getValue());
     }
     if ($tokenStream->nextIf(Token::T_TYPE, 'glob')) {
         $tokenStream->expect(Token::T_COLON);
     }
     return new Glob(Glob::encode($tokenStream->expect(static::$allowedTypes)->getValue()));
 }
 /**
  * @inheritdoc
  */
 public function parse(TokenStream $tokenStream)
 {
     $tokenStream->expect(Token::T_OPERATOR, $this->getOperatorName());
     $tokenStream->expect(Token::T_OPEN_PARENTHESIS);
     $field = $tokenStream->expect(Token::T_STRING)->getValue();
     $tokenStream->expect(Token::T_COMMA);
     $value = $this->getParser()->getExpressionParser()->parseScalar($tokenStream);
     $tokenStream->expect(Token::T_CLOSE_PARENTHESIS);
     return $this->createNode($field, $value);
 }
Пример #5
0
 /**
  * @inheritdoc
  */
 public function parse(TokenStream $tokenStream)
 {
     $limit = null;
     $offset = null;
     $tokenStream->expect(Token::T_OPERATOR, 'limit');
     $tokenStream->expect(Token::T_OPEN_PARENTHESIS);
     $limit = (int) $tokenStream->expect(Token::T_INTEGER)->getValue();
     if ($tokenStream->nextIf(Token::T_COMMA)) {
         $offset = (int) $tokenStream->expect(Token::T_INTEGER)->getValue();
     }
     $tokenStream->expect(Token::T_CLOSE_PARENTHESIS);
     return new LimitNode($limit, $offset);
 }
Пример #6
0
 /**
  * @inheritdoc
  */
 public function parse(TokenStream $tokenStream)
 {
     $limit = null;
     $offset = null;
     $tokenStream->expect(Token::T_OPERATOR, 'limit');
     $tokenStream->expect(Token::T_OPEN_PARENTHESIS);
     $limit = $this->valueParser->parse($tokenStream);
     if ($tokenStream->nextIf(Token::T_COMMA)) {
         $offset = $this->valueParser->parse($tokenStream);
     }
     $tokenStream->expect(Token::T_CLOSE_PARENTHESIS);
     return new LimitNode($limit, $offset);
 }
Пример #7
0
 /**
  * @inheritdoc
  */
 public function parse(TokenStream $tokenStream)
 {
     $fields = [];
     $tokenStream->expect(Token::T_OPERATOR, 'select');
     $tokenStream->expect(Token::T_OPEN_PARENTHESIS);
     do {
         $fields[] = $this->fieldNameParser->parse($tokenStream);
         if (!$tokenStream->nextIf(Token::T_COMMA)) {
             break;
         }
     } while (true);
     $tokenStream->expect(Token::T_CLOSE_PARENTHESIS);
     return new SelectNode($fields);
 }
 /**
  * @inheritdoc
  */
 public function parse(TokenStream $tokenStream)
 {
     $tokenStream->expect(Token::T_OPERATOR, $this->getOperatorName());
     $tokenStream->expect(Token::T_OPEN_PARENTHESIS);
     $queries = [];
     do {
         $queries[] = $this->conditionParser->parse($tokenStream);
         if (!$tokenStream->nextIf(Token::T_COMMA)) {
             break;
         }
     } while (true);
     $tokenStream->expect(Token::T_CLOSE_PARENTHESIS);
     return $this->createNode($queries);
 }
Пример #9
0
 /**
  * @inheritdoc
  */
 public function parse(TokenStream $tokenStream)
 {
     $fields = [];
     $tokenStream->expect(Token::T_OPERATOR, 'sort');
     $tokenStream->expect(Token::T_OPEN_PARENTHESIS);
     do {
         $direction = $tokenStream->expect([Token::T_PLUS, Token::T_MINUS]);
         $fields[$this->fieldNameParser->parse($tokenStream)] = $direction->test(Token::T_PLUS) ? SortNode::SORT_ASC : SortNode::SORT_DESC;
         if (!$tokenStream->nextIf(Token::T_COMMA)) {
             break;
         }
     } while (true);
     $tokenStream->expect(Token::T_CLOSE_PARENTHESIS);
     return new SortNode($fields);
 }
Пример #10
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];
     }
 }
 /**
  * @inheritdoc
  */
 public function parse(TokenStream $tokenStream)
 {
     if ($tokenStream->nextIf(Token::T_TYPE, 'array')) {
         $tokenStream->expect(Token::T_COLON);
         return [$this->itemParser->parse($tokenStream)];
     } else {
         return parent::parse($tokenStream);
     }
 }
Пример #12
0
 /**
  * @inheritdoc
  */
 public function parse(TokenStream $tokenStream)
 {
     if (($typeToken = $tokenStream->nextIf(Token::T_TYPE)) !== null) {
         $tokenStream->expect(Token::T_COLON);
         $value = $this->getTypeCaster($typeToken->getValue())->typeCast($tokenStream->next());
     } else {
         $value = $this->getScalarValue($tokenStream->next());
     }
     return $value;
 }
Пример #13
0
 /**
  * @inheritdoc
  */
 public function parse(TokenStream $tokenStream)
 {
     $tokenStream->expect(Token::T_OPEN_PARENTHESIS);
     $values = [];
     do {
         $values[] = $this->itemParser->parse($tokenStream);
         if (!$tokenStream->nextIf(Token::T_COMMA)) {
             break;
         }
     } while (true);
     $tokenStream->expect(Token::T_CLOSE_PARENTHESIS);
     return $values;
 }
Пример #14
0
 /**
  * @param TokenStream $tokenStream
  * @return AbstractNode
  * @throws SyntaxErrorException
  */
 public function parse(TokenStream $tokenStream)
 {
     $fields = [];
     $tokenStream->expect(Token::T_OPERATOR, 'select');
     $tokenStream->expect(Token::T_OPEN_PARENTHESIS);
     do {
         if (($aggregate = $tokenStream->nextIf(Token::T_OPERATOR, $this->allowedFunctions)) !== null) {
             $tokenStream->expect(Token::T_OPEN_PARENTHESIS);
             $fields[] = new AggregateFunctionNode($aggregate->getValue(), $tokenStream->expect(Token::T_STRING)->getValue());
             $tokenStream->expect(Token::T_CLOSE_PARENTHESIS);
         } else {
             $fields[] = $tokenStream->expect(Token::T_STRING)->getValue();
         }
         if (!$tokenStream->nextIf(Token::T_COMMA)) {
             break;
         }
     } while (true);
     $tokenStream->expect(Token::T_CLOSE_PARENTHESIS);
     return new XSelectNode($fields);
 }
Пример #15
0
 /**
  * @inheritdoc
  */
 public function parse(TokenStream $tokenStream)
 {
     return (int) $tokenStream->expect(Token::T_INTEGER)->getValue();
 }
Пример #16
0
 public function parse(TokenStream $tokenStream)
 {
     $tokenStream->expect(Token::T_OPERATOR, 'elemMatch');
     $tokenStream->expect(Token::T_OPEN_PARENTHESIS);
     $field = $tokenStream->expect(Token::T_STRING)->getValue();
     $tokenStream->expect(Token::T_COMMA);
     $query = $this->queryParser->parse($tokenStream);
     if (!$query instanceof AbstractQueryNode) {
         throw new SyntaxErrorException(sprintf('"elemMatch" operator expects parameter "query" to be instance of "%s", "%s" given', AbstractQueryNode::class, get_class($query)));
     }
     $tokenStream->expect(Token::T_CLOSE_PARENTHESIS);
     return new ElemMatchNode($field, $query);
 }
Пример #17
0
 /**
  * @inheritdoc
  */
 public function parse(TokenStream $tokenStream)
 {
     return $tokenStream->expect(Token::T_STRING)->getValue();
 }
Пример #18
0
 public function parse(TokenStream $tokenStream)
 {
     $fields = [];
     $tokenStream->expect(Token::T_OPERATOR, 'groupby');
     $tokenStream->expect(Token::T_OPEN_PARENTHESIS);
     do {
         $fields[] = $tokenStream->expect(Token::T_STRING)->getValue();
         if (!$tokenStream->nextIf(Token::T_COMMA)) {
             break;
         }
     } while (true);
     $tokenStream->expect(Token::T_CLOSE_PARENTHESIS);
     return new GroupbyNode($fields);
 }
Пример #19
0
 /**
  * @inheritdoc
  */
 public function parse(TokenStream $tokenStream)
 {
     return $tokenStream->expect(T_IDENTIFIER)->getValue();
 }