function TokenStream::expect
Tests a token and returns it or throws a syntax error.
File
-
vendor/
twig/ twig/ src/ TokenStream.php, line 72
Class
- TokenStream
- Represents a token stream.
Namespace
TwigCode
public function expect($type, $value = null, ?string $message = null) : Token {
$token = $this->tokens[$this->current];
if (!$token->test($type, $value)) {
$line = $token->getLine();
throw new SyntaxError(\sprintf('%sUnexpected token "%s"%s ("%s" expected%s).', $message ? $message . '. ' : '', Token::typeToEnglish($token->getType()), $token->getValue() ? \sprintf(' of value "%s"', $token->getValue()) : '', Token::typeToEnglish($type), $value ? \sprintf(' with value "%s"', $value) : ''), $line, $this->source);
}
$this->next();
return $token;
}