def replace_ref(tokens: list) -> list:
    """Replace a sublist of X, Y, 'R' into a unique R namedtuple."""
    size = len(tokens)
    new_list = []
    i = 0
    while i < size:
        if i < size - 2 and tokens[i + 2]  == 'R':
            new_list.append(complex(0, tokens[i]))
            i += 3
        else:
            new_list.append(tokens[i])
            i += 1
    return new_list
Replace a sublist of X, Y, 'R' into a unique R namedtuple.
pdfsyntax/objects.py