def METHOD_NAME(self, type_, value=None):
    if self.type != type_:
        self._raise_error("expected %s, got %s [%s]",
                          type_, self.type, self.value)
    if value is not None and self.value != value:
        self._raise_error("expected %s, got %s", value, self.value)
    value = self.value
    self._gettoken()
    return value