## vim: filetype=python

def token_match(self, other):
    """
    Helper for the finditer/find/findall methods, so that a token matches
    another token even if they are not strictly equivalent.
    """
    return self == other or self.text == other


@property
def full_name(n):
    """
    Return a nicely pretty printed name for any expr that is only formed of
    DottedName and Identifier instances.
    """
    if isinstance(n, DottedName):
        return "{}.{}".format(n.f_prefix.full_name, n.f_suffix.full_name)
    elif isinstance(n, BaseId):
        return n.text
    else:
        raise Exception("Wrong type for name: {}".format(type(n)))


Token.match = token_match
Name.full_name = full_name
