Parse special 'evolve blocks' from code. These blocks are marked with '# EVOLVE-BLOCK-START' and '# EVOLVE-BLOCK-END' comments. Args: code: The source code string containing evolve blocks. Returns: A list of tuples, where each tuple is (start_line, end_line, block_
(code: str)
| 9 | |
| 10 | |
| 11 | def parse_evolve_blocks(code: str) -> List[Tuple[int, int, str]]: |
| 12 | """ |
| 13 | Parse special 'evolve blocks' from code. These blocks are marked with |
| 14 | '# EVOLVE-BLOCK-START' and '# EVOLVE-BLOCK-END' comments. |
| 15 | |
| 16 | Args: |
| 17 | code: The source code string containing evolve blocks. |
| 18 | |
| 19 | Returns: |
| 20 | A list of tuples, where each tuple is (start_line, end_line, block_content). |
| 21 | """ |
| 22 | # Split the code into individual lines for processing |
| 23 | lines = code.split("\n") |
| 24 | blocks = [] |
| 25 | |
| 26 | in_block = False |
| 27 | start_line = -1 |
| 28 | block_content = [] |
| 29 | |
| 30 | # Iterate through each line with its index |
| 31 | for i, line in enumerate(lines): |
| 32 | if "# EVOLVE-BLOCK-START" in line: |
| 33 | # When a start marker is found, begin a new block |
| 34 | in_block = True |
| 35 | start_line = i |
| 36 | block_content = [] |
| 37 | elif "# EVOLVE-BLOCK-END" in line and in_block: |
| 38 | # When an end marker is found while in a block, finalize the block |
| 39 | in_block = False |
| 40 | blocks.append((start_line, i, "\n".join(block_content))) |
| 41 | elif in_block: |
| 42 | # If inside a block, append the current line to the block's content |
| 43 | block_content.append(line) |
| 44 | |
| 45 | return blocks |
| 46 | |
| 47 | |
| 48 | def apply_diff( |
nothing calls this directly
no outgoing calls
no test coverage detected