Tests a token and returns it or throws a syntax error.
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;
}