Exemple #1
0
 /**
  * @param string $rql
  * @param array $expected
  * @return void
  *
  * @dataProvider dataTokenize()
  */
 public function testTokenize($rql, $expected)
 {
     $lexer = new Lexer();
     $stream = $lexer->tokenize($rql);
     $this->assertSame(count($stream), count($expected) + 1);
     foreach ($expected as $token) {
         list($value, $type) = $token;
         $this->assertSame($value, $stream->getCurrent()->getValue(), sprintf('"%s" != "%s"', $value, $stream->getCurrent()->getValue()));
         $this->assertSame($type, $stream->getCurrent()->getType(), sprintf('"%s" != "%s"', Token::getTypeName($type), Token::getTypeName($stream->getCurrent()->getType())));
         $stream->next();
     }
 }
Exemple #2
0
 /**
  * @param int|int[] $type
  * @param string|string[] $value
  * @return Token
  * @throws SyntaxErrorException If the current token isn't expected
  */
 public function expect($type, $value = null)
 {
     $token = $this->getCurrent();
     if (!$this->test($type, $value)) {
         throw new SyntaxErrorException(sprintf('Unexpected token "%s" (%s) (%s)', $token->getValue(), $token->getName(), $value === null ? sprintf('expected %s', implode('|', array_map(function ($type) {
             return Token::getTypeName($type);
         }, (array) $type))) : sprintf('expected %s (%s)', implode('|', array_map(function ($value) {
             return '"' . $value . '"';
         }, (array) $type)), implode('|', array_map(function ($type) {
             return Token::getTypeName($type);
         }, (array) $type)))));
     }
     $this->next();
     return $token;
 }