'Internal method. Returns a characteristic path of the
pattern tree. This method must be run for all leaves until the
linear subpatterns are merged into a single'

def leaf_to_root(self):

    node = self
    subp = []
    while node:
        if (node.type == TYPE_ALTERNATIVES):
            node.alternatives.append(subp)
            if (len(node.alternatives) == len(node.children)):
                subp = [tuple(node.alternatives)]
                node.alternatives = []
                node = node.parent
                continue
            else:
                node = node.parent
                subp = None
                break
        if (node.type == TYPE_GROUP):
            node.group.append(subp)
            if (len(node.group) == len(node.children)):
                subp = get_characteristic_subpattern(node.group)
                node.group = []
                node = node.parent
                continue
            else:
                node = node.parent
                subp = None
                break
        if ((node.type == token_labels.NAME) and node.name):
            subp.append(node.name)
        else:
            subp.append(node.type)
        node = node.parent
    return subp
