Return sorted (start_byte, end_byte) spans of every comment that lives inside a function body, excluding fenced regions and tooling pragmas.
(src: bytes)
| 121 | |
| 122 | |
| 123 | def _inbody_comment_spans(src: bytes) -> list[tuple[int, int]]: |
| 124 | """Return sorted (start_byte, end_byte) spans of every comment that lives |
| 125 | inside a function body, excluding fenced regions and tooling pragmas.""" |
| 126 | tree = _rules._CPP_PARSER.parse(src) |
| 127 | text = src.decode("utf-8", errors="replace") |
| 128 | mask = _fence_mask(text.split("\n")) |
| 129 | spans: list[tuple[int, int]] = [] |
| 130 | for node in _rules._walk(tree.root_node): |
| 131 | if node.type != "comment": |
| 132 | continue |
| 133 | if not _rules._comment_in_function_body(node): |
| 134 | continue |
| 135 | line_idx = node.start_point[0] |
| 136 | if 0 <= line_idx < len(mask) and mask[line_idx]: |
| 137 | continue |
| 138 | if _rules._is_inbody_pragma(_rules._node_text(node, src)): |
| 139 | continue |
| 140 | spans.append((node.start_byte, node.end_byte)) |
| 141 | spans.sort() |
| 142 | return spans |
| 143 | |
| 144 | |
| 145 | def _strip_text(src_text: str) -> str: |
no test coverage detected