def METHOD_NAME(self, node):
    if isinstance(node, tuple):
        element, key, parents, flag = node
    else:
        return None
    if flag == "text":
        if not parents:
            return element
        else:
            return element, key, parents, None
    else:
        parent = parents.pop()
        if not parents:
            return parent
        else:
            assert list(parents[-1]).count(parent) == 1
            return parent, list(parents[-1]).index(parent), parents, None