Пример #1
0
 /**
  * Attempts to match the given token with the current lookahead token.
  * If they match, updates the lookahead token; otherwise raises a syntax error.
  *
  * @param int|string token type or value
  * @return bool True if tokens match; false otherwise.
  */
 public function match($token)
 {
     if (!($this->_lexer->lookahead['type'] === $token)) {
         $this->syntaxError($this->_lexer->getLiteral($token));
     }
     $this->_lexer->moveNext();
 }
Пример #2
0
 /**
  * SelectField ::= DocumentFieldName
  */
 public function SelectField(Query $query)
 {
     if ($this->lexer->isNextToken(Lexer::T_DISTINCT)) {
         $this->match(Lexer::T_DISTINCT);
         $fieldName = $this->DocumentFieldName();
         $query->distinct($fieldName);
         if (!$this->lexer->isNextToken(Lexer::T_IDENTIFIER) && !$this->lexer->isNextToken(Lexer::T_FROM)) {
             $this->syntaxError($this->lexer->getLiteral(Lexer::T_IDENTIFIER));
         }
         return;
     } else {
         $fieldName = $this->DocumentFieldName();
     }
     $limit = null;
     $skip = null;
     while ($this->lexer->isNextToken($this->lexer->lookahead['type'])) {
         switch ($this->lexer->lookahead['type']) {
             case Lexer::T_SKIP:
                 $this->match(Lexer::T_SKIP);
                 $this->match(Lexer::T_INTEGER);
                 $skip = $this->lexer->token['value'];
                 break;
             case Lexer::T_LIMIT:
                 $this->match(Lexer::T_LIMIT);
                 $this->match(Lexer::T_INTEGER);
                 $limit = $this->lexer->token['value'];
                 break;
             default:
                 break 2;
         }
     }
     if ($skip || $limit) {
         $skip = $skip !== null ? $skip : 0;
         $query->selectSlice($fieldName, $skip, $limit);
     } else {
         $query->select($fieldName);
     }
 }