@@ -0,0 +1,1057 @@
+import re%0A%0A%0Adef get_pairs_sym(data, sym_open, sym_close):%0A    positions = %5B%5D%0A    for m in re.finditer(sym_open, data):%0A        positions.append((m.start(), 0))%0A%0A    for m in re.finditer(sym_close, data):%0A        positions.append((m.start(), 1))%0A%0A    positions.sort()%0A%0A    i = 0%0A    while True:%0A        i += 1%0A        if i %3E= len(positions):%0A            break%0A%0A        (pos, t) = positions%5Bi%5D%0A        if t != 1:%0A            continue%0A%0A        for j in range(1, i + 1):%0A            (jpos, jt) = positions%5Bi - j%5D%0A            if jt != 0:%0A                continue%0A%0A            positions%5Bi - j%5D = (jpos, 99)%0A            positions%5Bi%5D = (pos, 99)%0A%0A            yield (jpos, pos)%0A            i = i - j - 1%0A            break%0A%0A%0Adef get_last_pair_sym(data, sym_open, sym_close):%0A    pairs = list(get_pairs_sym(data, sym_open, sym_close))%0A    if len(pairs):%0A        return pairs%5B-1%5D%0A%0A    return None%0A%0A%0Adef get_first_pair_sym(data, sym_open, sym_close):%0A    pairs = list(get_pairs_sym(data, sym_open, sym_close))%0A    if len(pairs):%0A        return pairs%5B0%5D%0A%0A    return None%0A

Add utility for parsing