def find_add_source_lines_calls()

in scripts/convert_addSourceLines_textblock.py [0:0]


def find_add_source_lines_calls(src: str) -> List[Tuple[int, int]]:
    """Return (open_paren_idx, close_paren_idx) pairs for addSourceLines calls."""
    calls = []
    i = 0
    n = len(src)
    state = "normal"
    while i < n:
        c = src[i]
        if state == "normal":
            if c == '"':
                state = "string"
            elif c == "'":
                state = "char"
            elif c == "/" and i + 1 < n and src[i + 1] == "/":
                state = "line_comment"
                i += 1
            elif c == "/" and i + 1 < n and src[i + 1] == "*":
                state = "block_comment"
                i += 1
            elif src.startswith("addSourceLines(", i):
                open_idx = i + len("addSourceLines")
                close_idx = find_matching_paren(src, open_idx)
                if close_idx is not None:
                    calls.append((open_idx, close_idx))
                    i = close_idx
        elif state == "string":
            if c == "\\":
                i += 1
            elif c == '"':
                state = "normal"
        elif state == "char":
            if c == "\\":
                i += 1
            elif c == "'":
                state = "normal"
        elif state == "line_comment":
            if c == "\n":
                state = "normal"
        elif state == "block_comment":
            if c == "*" and i + 1 < n and src[i + 1] == "/":
                state = "normal"
                i += 1
        i += 1
    return calls