def token_depth(token):
    """
    determines the "depth" of a regex 
    prefix tree. Used for guaranteeing
    unique node labels.
    """
    if token[0] == 'singleton':
        return 1
    else:
        depth = 0
        for operand in token[1][1:]:
            if token_depth(operand) > depth:
                depth = token_depth(operand)
        return depth + 1