You are here

public function Twig_TokenStream::expect in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/twig/twig/lib/Twig/TokenStream.php \Twig_TokenStream::expect()

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

Return value

Twig_Token

File

vendor/twig/twig/lib/Twig/TokenStream.php, line 82

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()), $token
      ->getValue(), Twig_Token::typeToEnglish($type), $value ? sprintf(' with value "%s"', $value) : ''), $line, $this->filename);
  }
  $this
    ->next();
  return $token;
}