syntaxError() public method

Generates a new syntax error.
public syntaxError ( string $expected = '', array $token = null )
$expected string Expected string.
$token array Got token.
 /**
  * @url http://sysmagazine.com/posts/181666/
  *
  * {@inheritdoc}
  */
 public function parse(Parser $parser)
 {
     $parser->match(Lexer::T_IDENTIFIER);
     $parser->match(Lexer::T_OPEN_PARENTHESIS);
     $lexer = $parser->getLexer();
     if ($lexer->isNextToken(Lexer::T_DISTINCT)) {
         $parser->match(Lexer::T_DISTINCT);
         $this->parameters[self::DISTINCT_KEY] = true;
     }
     // first Path Expression is mandatory
     $this->parameters[self::PARAMETER_KEY] = array();
     $this->parameters[self::PARAMETER_KEY][] = $parser->SingleValuedPathExpression();
     while ($lexer->isNextToken(Lexer::T_COMMA)) {
         $parser->match(Lexer::T_COMMA);
         $this->parameters[self::PARAMETER_KEY][] = $parser->StringPrimary();
     }
     if ($lexer->isNextToken(Lexer::T_ORDER)) {
         $this->parameters[self::ORDER_KEY] = $parser->OrderByClause();
     }
     if ($lexer->isNextToken(Lexer::T_IDENTIFIER)) {
         if (strtolower($lexer->lookahead['value']) !== 'separator') {
             $parser->syntaxError('separator');
         }
         $parser->match(Lexer::T_IDENTIFIER);
         $this->parameters[self::SEPARATOR_KEY] = $parser->StringPrimary();
     }
     $parser->match(Lexer::T_CLOSE_PARENTHESIS);
 }
 /**
  * @param Parser $parser
  */
 public function parse(Parser $parser)
 {
     // match
     $parser->match(Lexer::T_IDENTIFIER);
     $parser->match(Lexer::T_OPEN_PARENTHESIS);
     // first Path Expression is mandatory
     $this->pathExp = array();
     $this->pathExp[] = $parser->StateFieldPathExpression();
     // Subsequent Path Expressions are optional
     $lexer = $parser->getLexer();
     while ($lexer->isNextToken(Lexer::T_COMMA)) {
         $parser->match(Lexer::T_COMMA);
         $this->pathExp[] = $parser->StateFieldPathExpression();
     }
     $parser->match(Lexer::T_CLOSE_PARENTHESIS);
     // against
     if (strtolower($lexer->lookahead['value']) !== 'against') {
         $parser->syntaxError('against');
     }
     $parser->match(Lexer::T_IDENTIFIER);
     $parser->match(Lexer::T_OPEN_PARENTHESIS);
     $this->against = $parser->StringPrimary();
     if (strtolower($lexer->lookahead['value']) === 'boolean') {
         $parser->match(Lexer::T_IDENTIFIER);
         $this->booleanMode = true;
     }
     if (strtolower($lexer->lookahead['value']) === 'expand') {
         $parser->match(Lexer::T_IDENTIFIER);
         $this->queryExpansion = true;
     }
     $parser->match(Lexer::T_CLOSE_PARENTHESIS);
 }
Example #3
0
 public function parse(\Doctrine\ORM\Query\Parser $parser)
 {
     $parser->match(Lexer::T_IDENTIFIER);
     $parser->match(Lexer::T_OPEN_PARENTHESIS);
     $lexer = $parser->getLexer();
     if ($lexer->isNextToken(Lexer::T_DISTINCT)) {
         $parser->match(Lexer::T_DISTINCT);
         $this->isDistinct = true;
     }
     // first Path Expression is mandatory
     $this->pathExp = array();
     $this->pathExp[] = $parser->SingleValuedPathExpression();
     while ($lexer->isNextToken(Lexer::T_COMMA)) {
         $parser->match(Lexer::T_COMMA);
         $this->pathExp[] = $parser->StringPrimary();
     }
     if ($lexer->isNextToken(Lexer::T_ORDER)) {
         $this->orderBy = $parser->OrderByClause();
     }
     if ($lexer->isNextToken(Lexer::T_IDENTIFIER)) {
         if (strtolower($lexer->lookahead['value']) !== 'separator') {
             $parser->syntaxError('separator');
         }
         $parser->match(Lexer::T_IDENTIFIER);
         $this->separator = $parser->StringPrimary();
     }
     $parser->match(Lexer::T_CLOSE_PARENTHESIS);
 }
Example #4
0
 /**
  * {@inheritdoc}
  */
 public function parse(Parser $parser)
 {
     $parser->match(Lexer::T_IDENTIFIER);
     $parser->match(Lexer::T_OPEN_PARENTHESIS);
     $this->parameters[self::PARAMETER_KEY] = $parser->ArithmeticPrimary();
     $parser->match(Lexer::T_AS);
     $parser->match(Lexer::T_IDENTIFIER);
     $lexer = $parser->getLexer();
     $type = $lexer->token['value'];
     if ($lexer->isNextToken(Lexer::T_OPEN_PARENTHESIS)) {
         $parser->match(Lexer::T_OPEN_PARENTHESIS);
         /** @var Literal $parameter */
         $parameter = $parser->Literal();
         $parameters = array($parameter->value);
         if ($lexer->isNextToken(Lexer::T_COMMA)) {
             while ($lexer->isNextToken(Lexer::T_COMMA)) {
                 $parser->match(Lexer::T_COMMA);
                 $parameter = $parser->Literal();
                 $parameters[] = $parameter->value;
             }
         }
         $parser->match(Lexer::T_CLOSE_PARENTHESIS);
         $type .= '(' . implode(', ', $parameters) . ')';
     }
     if (!$this->checkType($type)) {
         $parser->syntaxError(sprintf('Type unsupported. Supported types are: "%s"', implode(', ', $this->supportedTypes)), $lexer->token);
     }
     $this->parameters[self::TYPE_KEY] = $type;
     $parser->match(Lexer::T_CLOSE_PARENTHESIS);
 }
Example #5
0
 /**
  * @inheritdoc
  */
 public function parse(Parser $parser)
 {
     $this->match = [];
     $this->mode = null;
     $parser->match(Lexer::T_IDENTIFIER);
     $parser->match(Lexer::T_OPEN_PARENTHESIS);
     $lexer = $parser->getLexer();
     for (;;) {
         $this->match[] = $parser->StateFieldPathExpression();
         if (!$lexer->isNextToken(Lexer::T_COMMA)) {
             break;
         }
         $parser->match(Lexer::T_COMMA);
     }
     $parser->match(Lexer::T_CLOSE_PARENTHESIS);
     if (strtoupper($lexer->lookahead['value']) !== 'AGAINST') {
         $parser->syntaxError('AGAINST');
     }
     $parser->match(Lexer::T_IDENTIFIER);
     $parser->match(Lexer::T_OPEN_PARENTHESIS);
     $this->against = $parser->StringPrimary();
     if ($lexer->isNextToken(Lexer::T_STRING)) {
         $parser->match(Lexer::T_STRING);
         $this->mode = $lexer->token['value'];
     }
     $parser->match(Lexer::T_CLOSE_PARENTHESIS);
 }
Example #6
0
 /**
  * @param Parser $parser
  * @throws QueryException
  */
 public function parse(Parser $parser)
 {
     $parser->match(Lexer::T_IDENTIFIER);
     $parser->match(Lexer::T_OPEN_PARENTHESIS);
     $lexer = $parser->getLexer();
     if ($lexer->isNextToken(Lexer::T_DISTINCT)) {
         $parser->match(Lexer::T_DISTINCT);
         $this->isDistinct = true;
     }
     $this->pathExpressions[] = $parser->SingleValuedPathExpression();
     while ($lexer->isNextToken(Lexer::T_COMMA)) {
         $parser->match(Lexer::T_COMMA);
         $this->pathExpressions[] = $parser->StringPrimary();
     }
     if ($lexer->isNextToken(Lexer::T_ORDER)) {
         $this->orderBy = $parser->OrderByClause();
     }
     if ($lexer->isNextToken(Lexer::T_IDENTIFIER)) {
         if (strtolower($lexer->lookahead['value']) !== self::T_SEPARATOR) {
             $parser->syntaxError(self::T_SEPARATOR);
         }
         $parser->match(Lexer::T_IDENTIFIER);
         $this->separator = $parser->StringPrimary();
     }
     $parser->match(Lexer::T_CLOSE_PARENTHESIS);
 }
Example #7
0
 /**
  * @inheritdoc
  */
 public function parse(Parser $parser)
 {
     $lexer = $parser->getLexer();
     $parser->match(Lexer::T_IDENTIFIER);
     $parser->match(Lexer::T_OPEN_PARENTHESIS);
     $this->listaggField = $parser->StringPrimary();
     if ($lexer->isNextToken(Lexer::T_COMMA)) {
         $parser->match(Lexer::T_COMMA);
         $this->separator = $parser->StringExpression();
     }
     $parser->match(Lexer::T_CLOSE_PARENTHESIS);
     if (!$lexer->isNextToken(Lexer::T_IDENTIFIER) || strtolower($lexer->lookahead['value']) != 'within') {
         $parser->syntaxError('WITHIN GROUP');
     }
     $parser->match(Lexer::T_IDENTIFIER);
     $parser->match(Lexer::T_GROUP);
     $parser->match(Lexer::T_OPEN_PARENTHESIS);
     $this->orderBy = $parser->OrderByClause();
     $parser->match(Lexer::T_CLOSE_PARENTHESIS);
     if ($lexer->isNextToken(Lexer::T_IDENTIFIER)) {
         if (strtolower($lexer->lookahead['value']) != 'over') {
             $parser->syntaxError('OVER');
         }
         $parser->match(Lexer::T_IDENTIFIER);
         $parser->match(Lexer::T_OPEN_PARENTHESIS);
         if (!$lexer->isNextToken(Lexer::T_IDENTIFIER) || strtolower($lexer->lookahead['value']) != 'partition') {
             $parser->syntaxError('PARTITION BY');
         }
         $parser->match(Lexer::T_IDENTIFIER);
         $parser->match(Lexer::T_BY);
         $this->partitionBy[] = $parser->StringPrimary();
         while ($lexer->isNextToken(Lexer::T_COMMA)) {
             $parser->match(Lexer::T_COMMA);
             $this->partitionBy[] = $parser->StringPrimary();
         }
         $parser->match(Lexer::T_CLOSE_PARENTHESIS);
     }
 }
Example #8
0
 public function parse(Parser $parser)
 {
     $lexer = $parser->getLexer();
     $parser->match(Lexer::T_IDENTIFIER);
     $parser->match(Lexer::T_OPEN_PARENTHESIS);
     $upperField = strtoupper($lexer->lookahead['value']);
     if ($lexer->lookahead['type'] !== Lexer::T_IDENTIFIER || !isset($this->formats[$upperField])) {
         $parser->syntaxError(implode('/', array_keys($this->formats)));
     }
     $parser->match(Lexer::T_IDENTIFIER);
     $this->field = $upperField;
     $parser->match(Lexer::T_FROM);
     $next = $lexer->glimpse();
     if (isset($next['type']) && $next['type'] === Lexer::T_STRING) {
         $upperType = strtoupper($lexer->lookahead['value']);
         if ($lexer->lookahead['type'] !== Lexer::T_IDENTIFIER || !in_array($upperType, $this->dateTimeTypes, true)) {
             $parser->syntaxError(implode('/', $this->dateTimeTypes));
         }
         $parser->match(Lexer::T_IDENTIFIER);
         $this->type = $upperType;
     }
     $this->source = $parser->ArithmeticPrimary();
     $parser->match(Lexer::T_CLOSE_PARENTHESIS);
 }
 /**
  * {@inheritdoc}
  */
 public function parse(Parser $parser)
 {
     $parser->match(Lexer::T_IDENTIFIER);
     $parser->match(Lexer::T_OPEN_PARENTHESIS);
     $parser->match(Lexer::T_IDENTIFIER);
     $lexer = $parser->getLexer();
     $unit = strtoupper(trim($lexer->token['value']));
     if (!$this->checkUnit($unit)) {
         $parser->syntaxError(sprintf('Unit is not valid for TIMESTAMPDIFF function. Supported units are: "%s"', implode(', ', $this->supportedUnits)), $lexer->token);
     }
     $this->parameters[self::UNIT_KEY] = $unit;
     $parser->match(Lexer::T_COMMA);
     $this->parameters[self::VAL1_KEY] = $parser->ArithmeticPrimary();
     $parser->match(Lexer::T_COMMA);
     $this->parameters[self::VAL2_KEY] = $parser->ArithmeticPrimary();
     $parser->match(Lexer::T_CLOSE_PARENTHESIS);
 }