MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / _inbody_comment_spans

Function _inbody_comment_spans

scripts/strip-inbody-comments.py:123–142  ·  view source on GitHub ↗

Return sorted (start_byte, end_byte) spans of every comment that lives inside a function body, excluding fenced regions and tooling pragmas.

(src: bytes)

Source from the content-addressed store, hash-verified

121
122
123def _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
145def _strip_text(src_text: str) -> str:

Callers 2

_strip_textFunction · 0.85
mainFunction · 0.85

Calls 3

_fence_maskFunction · 0.85
parseMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected