Emit a diagnostic when an injected block has an obvious brace imbalance.
(body: str, tag: str, source: str)
| 77 | |
| 78 | |
| 79 | def _check_brace_balance(body: str, tag: str, source: str) -> None: |
| 80 | """Emit a diagnostic when an injected block has an obvious brace |
| 81 | imbalance.""" |
| 82 | stripped = _strip_cpp_braces_in_strings(body) |
| 83 | opens = stripped.count("{") |
| 84 | closes = stripped.count("}") |
| 85 | if opens != closes: |
| 86 | _diag_add( |
| 87 | f"[diagnostic] {source}: injected block for tag " |
| 88 | f"CODEGEN_{tag} has unbalanced braces (open={opens}, " |
| 89 | f"close={closes}). The generated .cpp will not compile.", |
| 90 | source=source, |
| 91 | ) |
| 92 | |
| 93 | |
| 94 | _TAG_PATTERN_CACHE: Dict[str, "re.Pattern[str]"] = {} |
no test coverage detected