Generates a new syntax error.

@param string      $expected Expected string.
@param array|null  $token    Got token.

@return void

@throws ExpressionException
173566
public function syntaxError($expected = '', $token = null)
    {
        if ($token === null) {
            $token = $this->lexer->lookahead;
        }

        $tokenPos = (isset($token['position'])) ? $token['position'] : '-1';

        $message  = "line 0, col {$tokenPos}: Error: ";
        $message .= ($expected !== '') ? "Expected {$expected}, got " : 'Unexpected ';
        $message .= ($this->lexer->lookahead === null) ? 'end of string.' : "'{$token['value']}'";

        throw ExpressionException::syntaxError($message, ExpressionException::expressionError($this->expression));
    }
1238279
def SetExpression(self, expression):
    """"""
    if isinstance(expression, lexer.Expression):
      self.args = [expression]
    else:
      raise errors.ParseError(
          'Expected expression, got {0:s}.'.format(expression))
1071778
public Token expect(@Nonnull String expected, @Nonnull TokenValidator validator) throws IOException {
        if (!hasNext()) {
            throw eof("Expected %s, got end of file", expected);
        } else if (validator.validate(unreadToken)) {
            lastToken = unreadToken;
            unreadToken = null;
            return lastToken;
        }
        throw failure(unreadToken, "Expected %s, but got '%s'", expected, Strings.escape(unreadToken.asString()));
    }
25730
public function expect(string $char): void
    {
        $this->latestExpectations = [$char];

        $taken = $this->take();

        if ($taken !== $char) {
            $this->lastTaken = null;

            throw new UnexpectedChar($this, [$char]);
        }
    }
323676
public static function unexpectedCharacter(Input $definition, array $expected = []): self
    {
        $pointer = self::createPointerString($definition->getInput(), $definition->getIndex());

        if (empty($expected)) {
            return new self("Unexpected character:\n$pointer");
        }

        $expected = $expected ?? $definition->getLatestExpectations();

        $expected = array_map(function (string $e) {
            return "'$e'";
        }, $expected);

        $expected = implode(", ", $expected);

        return new self("Unexpected character (expected $expected):\n$pointer");
    }
286072
public function parse(Token $token): DynamicArrayValue
    {
        parent::parse($token);

        if (1 !== preg_match(self::REGEX, $token->getValue(), $matches)) {
            throw ExpressionLanguageExceptionFactory::createForUnparsableToken($token);
        }

        $quantifier = $this->parser->parse($matches['quantifier']);
        if (is_scalar($quantifier)) {
            $quantifier = (int) $quantifier;
        }

        return new DynamicArrayValue(
            $quantifier,
            $this->parser->parse($matches['elements'])
        );
    }
949746
public function parse(Token $token): FunctionCallValue
    {
        if (null === $this->parser) {
            throw ExpressionLanguageExceptionFactory::createForExpectedMethodCallOnlyIfHasAParser(__METHOD__);
        }

        if (1 !== preg_match(self::REGEX, $token->getValue(), $matches)) {
            throw ExpressionLanguageExceptionFactory::createForUnparsableToken($token);
        }

        $argumentEscaper = $this->argumentEscaper;

        $function = $matches['function'];
        if ('identity' === $function) {
            $value = preg_replace_callback(
                '/__ARG_TOKEN__[\da-z]{32}/',
                function (array $matches) use ($argumentEscaper): string {
                    return '\''.$argumentEscaper->unescape($matches[0]).'\'';
                },
                $matches['arguments']
            );

            $arguments = [new EvaluatedValue($value)];
        } elseif ('current' === $function) {
            $arguments = [new ValueForCurrentValue()];
        } else {
            $arguments = $this->parseArguments($this->parser, trim($matches['arguments']));
        }

        return new FunctionCallValue($function, $arguments);
    }
1112034
public function parse(Token $token)
    {
        $parser = $this->parser;
        $stream = $parser->getStream();

        $default = null;
        $cases = [];
        $end = false;

        $name = $parser->getExpressionParser()->parseExpression();
        $stream->expect(Token::BLOCK_END_TYPE);
        $stream->expect(Token::TEXT_TYPE);
        $stream->expect(Token::BLOCK_START_TYPE);
        while (!$end) {
            /** @var Token $v */
            $v = $stream->next();
            switch ($v->getValue()) {
                case 'default':
                    $stream->expect(Token::BLOCK_END_TYPE);
                    $default = $parser->subparse([$this, 'decideIfEnd']);
                    break;

                case 'case':
                    $expr = $parser->getExpressionParser()->parseExpression();
                    $stream->expect(Token::BLOCK_END_TYPE);
                    $body = $parser->subparse([$this, 'decideIfFork']);
                    $cases[] = $expr;
                    $cases[] = $body;
                    break;

                case 'endswitch':
                    $end = true;
                    break;

                default:
                    $message = sprintf('Unexpected end of template. Twig was looking for the following tags "case", "default", or "endswitch" to close the "switch" block started at line %d)', $v->getLine());

                    throw new SyntaxError($message, $v->getLine());
            }
        }

        $stream->expect(Token::BLOCK_END_TYPE);

        return new SwitchNode($name, new Node($cases), $default, $token->getLine(), $this->getTag());
    }
47243
private function insertNewLine(array $token): void
    {
        $fixer = $this->file->getFixer();
        $lineStartPadding = str_pad('', $token['column'] - 3, ' ');

        $fixer->beginChangeset();

        // Remove the whitespace between the tag and the comments star.
        $fixer->replaceToken($token['pointer'] - 1, '');

        $fixer->addContentBefore(
            $token['pointer'],
            $this->file->getEolChar() . $lineStartPadding . '* '
        );

        $fixer->endChangeset();
    }
533254
private void error(String expected, String actual) {
        if (!recovering) {
            recovering = true;
            final String outputString = (EOF_STRING.equals(actual) || UNTERMINATED_COMMENT_STRING.equals(actual) || COMMENT_NOT_ALLOWED.equals(actual)) ? actual : "'"
                    + actual + "'";
            errors.add(SyntaxError._UnexpectedToken(expected, outputString,
                    lookahead(1).beginLine));
        }
    }
995022
public function parse(Token $token)
    {
        $lineno = $token->getLine();
        $stream = $this->parser->getStream();

        $count = null;
        $vars = new ArrayExpression([], $lineno);
        $domain = null;
        $locale = null;
        if (!$stream->test(Token::BLOCK_END_TYPE)) {
            if ($stream->test('count')) {
                // {% trans count 5 %}
                $stream->next();
                $count = $this->parser->getExpressionParser()->parseExpression();
            }

            if ($stream->test('with')) {
                // {% trans with vars %}
                $stream->next();
                $vars = $this->parser->getExpressionParser()->parseExpression();
            }

            if ($stream->test('from')) {
                // {% trans from "messages" %}
                $stream->next();
                $domain = $this->parser->getExpressionParser()->parseExpression();
            }

            if ($stream->test('into')) {
                // {% trans into "fr" %}
                $stream->next();
                $locale = $this->parser->getExpressionParser()->parseExpression();
            } elseif (!$stream->test(Token::BLOCK_END_TYPE)) {
                throw new SyntaxError('Unexpected token. Twig was looking for the "with", "from", or "into" keyword.', $stream->getCurrent()->getLine(), $stream->getSourceContext());
            }
        }

        // {% trans %}message{% endtrans %}
        $stream->expect(Token::BLOCK_END_TYPE);
        $body = $this->parser->subparse([$this, 'decideTransFork'], true);

        if (!$body instanceof TextNode && !$body instanceof AbstractExpression) {
            throw new SyntaxError('A message inside a trans tag must be a simple text.', $body->getTemplateLine(), $stream->getSourceContext());
        }

        $stream->expect(Token::BLOCK_END_TYPE);

        return new TransNode($body, $domain, $count, $vars, $locale, $lineno, $this->getTag());
    }
168081
public function syntaxError($expected = '', $token = null)
    {
        if ($token === null) {
            $token = $this->lexer->lookahead;
        }

        $tokenPos = (isset($token['position'])) ? $token['position'] : '-1';

        $message  = "line 0, col {$tokenPos}: Error: ";
        $message .= ($expected !== '') ? "Expected {$expected}, got " : 'Unexpected ';
        $message .= ($this->lexer->lookahead === null) ? 'end of string.' : "'{$token['value']}'";

        throw QueryException::syntaxError($message, QueryException::dqlError($this->query->getDQL()));
    }
1186641
@Nonnull
    public Token expect(@Nonnull String expected) throws IOException {
        if (!hasNext()) {
            throw eof("Expected %s: Got end of file", expected);
        }
        lastToken = unreadToken;
        unreadToken = null;
        return lastToken;
    }
261697
private static function expect($expected, $token)
    {
        if (!in_array($token['type'], $expected)) {
            if (count($expected) === 1) {
                $expectedStr = self::tokenName($expected[0]);
            } else {
                $last = array_pop($expected);
                $expectedStr = 'one of ' . implode(', ', array_map(['self', 'tokenName'], $expected)) . ' or ' . self::tokenName($last);
            }
            $actualStr = self::tokenName($token['type']);
            if ($token['match']) {
                $actualStr .= " ('" . addslashes($token['match']) . "')";
            }
            $actualStr .= ' <<< ' . Json::dump($token) . ' >>> ';
            throw new PermissionParserException("Parser error: expected $expectedStr, but found $actualStr");
        }
    }
667293
public static function expected($expected, $code = 0)
    {
        if ($expected === null || is_string($expected)) {
            return new AnyException($expected, $code);
        }
        return $expected;
    }
1119038
protected function validateExpectationOrThrowException(Expectation $expectation, LoggerInterface $logger)
    {
        $this->validateRequestOrThrowException($expectation, $logger);
        $this->validateResponseOrThrowException($expectation, $logger);
        $this->validateScenarioConfigOrThrowException($expectation, $logger);
    }
108096
protected function handleConditional(array $token)
    {

        $node = $this->createNode('conditional', $token);
        $node->subject = $token['subject'];
        $node->conditionType = $token['conditionType'];

        $this->current = $node;
    }