import re


def _parse_list_of_list_of_antpairs(input_str):
    """
    Parse a text string as a list of list of antpairs.

    Note
    ----
    This function is used for the `reds` key to return groups
    of redundant baselines.

    Parameters
    ----------
    input_str : str
        The input string to be processed.

    Returns
    -------
    output : list
        A list containing the parsed set of antpairs.
    """
    # use regex to extract lists
    list_regex = r"\[(.*?)\]"
    lists = re.findall(list_regex, input_str[1:-1])

    # initialize output
    output = []
    for li in lists:
        sublist = []
        tuple_regex = r"\((.*?)\)"
        tuples = re.findall(tuple_regex, li)
        for tup in tuples:
            ant1, ant2 = tup.split(",")
            sublist.append(tuple((int(ant1), int(ant2))))
        output.append(sublist)
    return output