/** * Tests the current token for a condition or throws an exception otherwise. * * @param array|integer $type * @param array|string|null $value * @param string|null $message * @throws SyntaxErrorException * @return Token|null */ public function expect($type, $value = null, $message = null) { $token = $this->tokens[$this->current]; if (!$token->test($type, $value)) { throw new SyntaxErrorException(sprintf('%sUnexpected token "%s" of value "%s" ("%s" expected%s) on line %s', $message ? "{$message}. " : "", $token, $token->getValue(), Token::getName($type), $value ? sprintf(' with value "%s"', $value) : '', $token->getLine())); } return $token; }