public function Twig_TokenStream::expect

Tests a token and returns it or throws a syntax error.

Return value

Twig_Token

File

drupal/core/vendor/twig/twig/lib/Twig/TokenStream.php, line 71

Class

Twig_TokenStream
Represents a token stream.

Code

public function expect($type, $value = null, $message = null) {
  $token = $this->tokens[$this->current];
  if (!$token
    ->test($type, $value)) {
    $line = $token
      ->getLine();
    throw new Twig_Error_Syntax(sprintf('%sUnexpected token "%s" of value "%s" ("%s" expected%s)', $message ? $message . '. ' : '', Twig_Token::typeToEnglish($token
      ->getType(), $line), $token
      ->getValue(), Twig_Token::typeToEnglish($type, $line), $value ? sprintf(' with value "%s"', $value) : ''), $line, $this->filename);
  }
  $this
    ->next();
  return $token;
}