'Returns ``True`` if this token is within *group_cls*.
Use this method for example to check if an identifier is within
a function: ``t.within(sql.Function)``.'

def within(self, group_cls):

    parent = self.parent
    while parent:
        if isinstance(parent, group_cls):
            return True
        parent = parent.parent
    return False
