MCPcopy Create free account
hub / github.com/Graphify-Labs/graphify / _normalize_cpp_directive_comments

Function _normalize_cpp_directive_comments

graphify/extract.py:3897–3924  ·  view source on GitHub ↗

Blank closed block comments inside ``define`` directive spans. Unterminated comments and comments spanning an unspliced newline are left unchanged.

(source: bytes)

Source from the content-addressed store, hash-verified

3895
3896
3897def _normalize_cpp_directive_comments(source: bytes) -> bytes:
3898 """Blank closed block comments inside ``define`` directive spans.
3899
3900 Unterminated comments and comments spanning an unspliced newline are left
3901 unchanged.
3902 """
3903 if b"/*" not in source:
3904 return source
3905 out: bytearray | None = None
3906 for directive, _ in _cpp_conditional_tokens(source):
3907 if directive.group(2) != b"define":
3908 continue
3909 if source[max(0, directive.start() - 3):directive.start()].endswith(
3910 (b"\\\n", b"\\\r\n")
3911 ):
3912 continue
3913 text = directive.group()
3914 if b"/*" not in text:
3915 continue
3916 for token in _CPP_DIRECTIVE_COMMENT_RE.finditer(text):
3917 if token.group("comment") is None:
3918 continue
3919 if out is None:
3920 out = bytearray(source)
3921 start = directive.start() + token.start()
3922 end = directive.start() + token.end()
3923 out[start:end] = _blank_cpp_comment_keeping_splices(token.group())
3924 return bytes(out) if out is not None else source
3925
3926
3927def _cpp_conditional_groups(source: bytes) -> tuple[list[dict], str | None]:

Calls 3

_cpp_conditional_tokensFunction · 0.85
startMethod · 0.45