<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def consume(self, expect_class=None):
 """Retrieve the current token, then advance the parser. If an expected class is provided, it will assert that the current token matches that class (is an instance). Note that when calling a token's nud() or led() functions, the "current" token is the token following the token whose method has been called. Returns: Token: the previous current token. Raises: InvalidTokenError: If an expect_class is provided and the current token doesn't match that class. """

        if expect_class and not isinstance(self.current_token, expect_class):
            raise InvalidTokenError("Unexpected token at %d: got %r, expected %s" % (
                self.current_pos, self.current_token, expect_class.__name__))

        current_token = self.current_token
        self._forward()
        return current_token