/**
  * @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);
     }
 }
Пример #2
0
 /**
  * @inheritdoc
  */
 public function parseScalar(TokenStream $tokenStream)
 {
     if (($typeToken = $tokenStream->nextIf(Token::T_TYPE)) !== null) {
         $value = $this->getTypeCaster($typeToken->getValue())->typeCast($tokenStream->next());
     } else {
         $value = $this->getScalarValue($tokenStream->next());
     }
     return $value;
 }
Пример #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()));
 }
Пример #4
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);
 }
Пример #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)
 {
     $fields = [];
     $tokenStream->expect(Token::T_OPERATOR, 'select');
     $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 SelectNode($fields);
 }
Пример #7
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[$tokenStream->expect(Token::T_STRING)->getValue()] = $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);
 }
Пример #8
0
 /**
  * @inheritDoc
  */
 public function parse(TokenStream $tokenStream)
 {
     $token = $tokenStream->getCurrent();
     if ($tokenStream->nextIf(Token::T_FALSE)) {
         return false;
     } elseif ($tokenStream->nextIf(Token::T_TRUE)) {
         return true;
     } elseif ($tokenStream->nextIf(Token::T_NULL)) {
         return null;
     } elseif ($tokenStream->nextIf(Token::T_DATE)) {
         return new \DateTime($token->getValue());
     } elseif ($tokenStream->nextIf(Token::T_STRING)) {
         return $token->getValue();
     } elseif ($tokenStream->nextIf(Token::T_INTEGER)) {
         return (int) $token->getValue();
     } elseif ($tokenStream->nextIf(Token::T_FLOAT)) {
         return (double) $token->getValue();
     }
     throw new SyntaxErrorException(sprintf('Invalid scalar token "%s" (%s)', $token->getValue(), $token->getName()));
 }