MCPcopy
hub / github.com/tirth8205/code-review-graph / _strip_rescript_noise

Function _strip_rescript_noise

code_review_graph/parser.py:613–677  ·  view source on GitHub ↗

Replace ReScript comments and string/backtick content with spaces. Newlines are preserved so absolute offsets still map back to accurate line numbers. ReScript block comments may nest, so we track depth.

(text: str)

Source from the content-addressed store, hash-verified

611
612
613def _strip_rescript_noise(text: str) -> str:
614 """Replace ReScript comments and string/backtick content with spaces.
615
616 Newlines are preserved so absolute offsets still map back to accurate
617 line numbers. ReScript block comments may nest, so we track depth.
618 """
619 out: list[str] = []
620 i = 0
621 n = len(text)
622 while i < n:
623 c = text[i]
624 nxt = text[i + 1] if i + 1 < n else ""
625 # Line comment
626 if c == "/" and nxt == "/":
627 while i < n and text[i] != "\n":
628 out.append(" ")
629 i += 1
630 continue
631 # Nestable block comment
632 if c == "/" and nxt == "*":
633 depth = 1
634 out.append(" ")
635 i += 2
636 while i < n and depth > 0:
637 if i + 1 < n and text[i] == "/" and text[i + 1] == "*":
638 depth += 1
639 out.append(" ")
640 i += 2
641 elif i + 1 < n and text[i] == "*" and text[i + 1] == "/":
642 depth -= 1
643 out.append(" ")
644 i += 2
645 else:
646 out.append("\n" if text[i] == "\n" else " ")
647 i += 1
648 continue
649 # Double-quoted string — blank content, keep quotes + newlines.
650 if c == '"':
651 out.append('"')
652 i += 1
653 while i < n and text[i] != '"':
654 if text[i] == "\\" and i + 1 < n:
655 out.append(" ")
656 i += 2
657 continue
658 out.append("\n" if text[i] == "\n" else " ")
659 i += 1
660 if i < n:
661 out.append('"')
662 i += 1
663 continue
664 # Backtick template string — blank content, preserve newlines.
665 if c == "`":
666 out.append("`")
667 i += 1
668 while i < n and text[i] != "`":
669 out.append("\n" if text[i] == "\n" else " ")
670 i += 1

Callers 1

_parse_rescriptMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected