Generates a new syntax error.

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

@return void

@throws \Doctrine\ORM\Query\QueryException
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()));
    }
196667
private static String initialise(Token currentToken,
                           int[][] expectedTokenSequences,
                           String[] tokenImage) {
    StringBuffer expected = new StringBuffer();
    
    //149852 - This was removed due to a findBugs error we felt was worthy of a change.
    //Added in a doPrivileged call around the getProperty call
    String eol;
    if(System.getSecurityManager() != null){
    	eol = AccessController.doPrivileged(
                new PrivilegedAction<String>(){
                    @Override
                    public String run() {
                        return System.getProperty("line.separator", "\n");
                    }
                }
  		  );
    } else {
    	eol = System.getProperty("line.separator", "\n");
    }
    int maxSize = 0;
    for (int i = 0; i < expectedTokenSequences.length; i++) {
      if (maxSize < expectedTokenSequences[i].length) {
        maxSize = expectedTokenSequences[i].length;
      }
      for (int j = 0; j < expectedTokenSequences[i].length; j++) {
        expected.append(tokenImage[expectedTokenSequences[i][j]]).append(' ');
      }
      if (expectedTokenSequences[i][expectedTokenSequences[i].length - 1] != 0) {
        expected.append("...");
      }
      expected.append(eol).append("    ");
    }
    String retval = "Encountered \"";
    Token tok = currentToken.next;
    for (int i = 0; i < maxSize; i++) {
      if (i != 0) retval += " ";
      if (tok.kind == 0) {
        retval += tokenImage[0];
        break;
      }
      retval += " " + tokenImage[tok.kind];
      retval += " \"";
      retval += add_escapes(tok.image);
      retval += " \"";
      tok = tok.next;
    }
    retval += "\" at line " + currentToken.next.beginLine + ", column " + currentToken.next.beginColumn;
    retval += "." + eol;
    if (expectedTokenSequences.length == 1) {
      retval += "Was expecting:" + eol + "    ";
    } else {
      retval += "Was expecting one of:" + eol + "    ";
    }
    retval += expected.toString();
    return retval;
  }
394507
private static String initialise(Token currentToken,
                           int[][] expectedTokenSequences,
                           String[] tokenImage) {
    String eol = System.getProperty("line.separator", "\n");
    StringBuffer expected = new StringBuffer();
    int maxSize = 0;
    for (int i = 0; i < expectedTokenSequences.length; i++) {
      if (maxSize < expectedTokenSequences[i].length) {
        maxSize = expectedTokenSequences[i].length;
      }
      for (int j = 0; j < expectedTokenSequences[i].length; j++) {
        expected.append(tokenImage[expectedTokenSequences[i][j]]).append(' ');
      }
      if (expectedTokenSequences[i][expectedTokenSequences[i].length - 1] != 0) {
        expected.append("...");
      }
      expected.append(eol).append("    ");
    }
    String retval = "Encountered \"";
    Token tok = currentToken.next;
    for (int i = 0; i < maxSize; i++) {
      if (i != 0) retval += " ";
      if (tok.kind == 0) {
        retval += tokenImage[0];
        break;
      }
      retval += " " + tokenImage[tok.kind];
      retval += " \"";
      retval += add_escapes(tok.image);
      retval += " \"";
      tok = tok.next;
    }
    retval += "\" at line " + currentToken.next.beginLine + ", column " + currentToken.next.beginColumn;
    retval += "." + eol;
    if (expectedTokenSequences.length == 1) {
      retval += "Was expecting:" + eol + "    ";
    } else {
      retval += "Was expecting one of:" + eol + "    ";
    }
    retval += expected.toString();
    return retval;
  }
972566
def expect_keyword(lexer: Lexer, value: str) -> Token:
    
    token = lexer.token
    if token.kind == TokenKind.NAME and token.value == value:
        lexer.advance()
        return token

    raise GraphQLSyntaxError(
        lexer.source, token.start, f"Expected {value!r}, found {token.desc}"
    )
25286
public function expectExplicit($expectedTag = null): ExplicitTagging
    {
        $el = $this;
        if (!$el instanceof ExplicitTagging) {
            throw new \UnexpectedValueException(
                "Element doesn't implement explicit tagging.");
        }
        if (isset($expectedTag)) {
            $el->expectTagged($expectedTag);
        }
        return $el;
    }
93560
public function createExpectation(Expectation $expectation)
    {
        $uri = $this->createBaseUri()->withPath(self::API_EXPECTATIONS_URL);
        $body = @json_encode($expectation);
        if (false === $body) {
            throw new \RuntimeException('Error generating json body for request: ' . json_last_error_msg());
        }
        $request = (new PsrRequest())
            ->withUri($uri)
            ->withMethod('post')
            ->withHeader('Content-Type', 'application/json')
            ->withBody(new StringStream($body));
        $this->checkResponse($this->connection->send($request));
    }
272649
public function verify()
    {
        if ($this->currentIndex < $this->sequenceIndex) {
            throw new PHPUnit_Framework_ExpectationFailedException(
              sprintf(
                "The expected invocation at method '%s' index %d was never reached.",

                $this->method,
                $this->sequenceIndex
              )
            );
        }
    }
110440
private function _checkProhibitedKeywordsRegex($token) {
		if ($this->_isActive('checkProhibitedKeywordsRegex')) {

			foreach ($this->_prohibitedKeywordsRegex as $pattern) {

				preg_match_all($pattern, $token->text, $matches);
				$matches = $matches[0];
				if (!empty($matches)) {
					foreach ($matches as $key => $value) {
						$msg = $this->_getMessage('PROHIBITED_KEYWORD_REGEX', $value);
						$this->_writeError('checkProhibitedKeywordsRegex', $msg);
					}
				}
			}
		}
	}
1182686
public function expects($type, $value = null)
    {
        $token = $this->tokens[$this->cursor];

        if (($value === null ? $token->is($type) : $token->equals($type, $value)) === false) {
            throw new UnexpectedTokenException($this, new Token($type, $value));
        }

        return $this->tokens[$this->cursor++];
    }
21539
protected function validateExpectationOrThrowException(MockConfig $expectation, LoggerInterface $logger)
    {
        $this->logger->debug('Adding Expectation->validateExpectationOrThrowException');
        $this->validateRequestOrThrowException($expectation, $logger);
        $this->validateResponseOrThrowException($expectation, $logger);
        $this->validateScenarioConfigOrThrowException($expectation, $logger);
    }
656213
protected function handleEach(array $token)
    {

        $node = $this->createNode('each', $token);
        $node->subject = $token['subject'];
        $node->itemName = $token['itemName'];
        $node->keyName = isset($token['keyName']) ? $token['keyName'] : null;

        $this->current = $node;
    }
412399
public function unexpected($token, $className = '\\JsPhpize\\Lexer\\Exception')
    {
        return new $className('Unexpected ' . $token->type . rtrim(' ' . ($token->value ?: '')) . $this->exceptionInfos(), 8);
    }
1240841
protected function renderFunction(Value $token)
    {

        $open = $this->query->getNextToken();
        if (empty($open)) {
            throw new QueryException("Unexpected end of token sequence. Expecting 'open parentheses' token for a function");
        }

        $sql =
            $this->renderValue($token) .                    // function name
            $this->renderToken($open);     // open parentheses

        // get the next token and keep adding SQL to the arguments array until we hit a "close parentheses" token
        $token = $this->query->getNextToken();
        $arguments = [];
        $argumentFinished = true;
        $lastArgument = null;
        $continuationTokens = ["operator" => true, "open" => true, "close" => true];
        $level = 1;

        while (!empty($token) && !($token->getType() == "close" && $level == 1)) {
            $type = $token->getType();
            if (isset($continuationTokens[$type])) {
                // if this is a continuation token, render it and set the argument finished flag to false
                if ($type == "open") {
                    ++$level;
                } elseif ($type == "close") {
                    --$level;
                }
                $argumentFinished = false;
                $tokenSql = $this->renderToken($token);
                // if this happens to be the first token, start a new argument, otherwise continue the last one
                if (!is_null($lastArgument)) {
                    $arguments[$lastArgument] .= " " . $tokenSql;
                } else {
                    $arguments[] = $tokenSql;
                    $lastArgument = 0;
                }
            } elseif (!$argumentFinished) {
                // if we're not finished with the last argument, add this token to it

                $arguments[$lastArgument] .= " " . $this->renderToken($token);
                $argumentFinished = true;
            } else {
                // otherwise, start a new argument
                $arguments[] = $this->renderToken($token);
                $lastArgument = count($arguments) - 1;
            }
            $token = $this->query->getNextToken();
        }
        $sql .= implode(", ", $arguments); // add the arguments to the SQL

        if (empty($token)) {
            throw new QueryException("Unexpected end of token sequence. Expecting 'close parentheses' token for a function: $sql");
        }
        $sql .= $this->renderToken($token); // close parentheses
        return $sql;
    }
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");
    }
688337
protected function expect(string $kind): Token
    {
        $token = $this->lexer->getToken();

        if ($kind === $token->getKind()) {
            $this->lexer->advance();
            return $token;
        }

        throw $this->lexer->createSyntaxErrorException(\sprintf('Expected %s, found %s.', $kind, $token));
    }
425183
public function setExpectedAndReceived($expected, $received)
    {
        $this->expected = is_string($expected)
            ? $expected : get_class($expected);

        $this->received = TypeHound::fetch($received);

        $this->message = vsprintf(
            'An instance of a %s was expected but got %s',
            [$this->expected, $this->received]
        );
    }
1141662
protected function write(string $line, $expectedCode = null, string $message = null): void
    {
        \fwrite($this->connection, $line . Message::EOL);
        if ($expectedCode) {
            $response = $this->read();
            if (!\in_array((int) $response, (array) $expectedCode, true)) {
                throw new SmtpException('SMTP server did not accept ' . ($message ?: $line) . ' with error: ' . \trim($response));
            }
        }
    }