Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. TokenStream.php

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

Twig

Code

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;
}
RSS feed
Powered by Drupal