feat(tools): strip FEEL comments in the ingester slice predicate
public
feat(tools): strip FEEL comments in the ingester slice predicate Add `strip_comments(expr)` — a string-aware helper that removes `//…` (EOL) and `/*…*/` (block) comments before `fits_slice_grammar` scans for free identifiers. Without this, comment words would be seen as unbound names and the case would be wrongly skipped. The raw expression is preserved in the fixture (feel-core now handles comments); only the predicate strips them for the heuristic scan. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
| Changeset | 5cdabf19dd1f4c0255d2774f9eadba8910175a59 |
|---|---|
| Author (claimed) | Timo Stolz <timo.stolz@gmail.com>, |
| Parents | 7cb5fe8a93eb |
| Children | |
| Pushlog | by timo via ssh |
modified tools/ingest_tck.py +41 −0
| @@ -223,6 +223,44 @@ | ||
| 223 | 223 | return True |
| 224 | 224 | |
| 225 | 225 | |
| 226 | +def strip_comments(expr: str) -> str: | |
| 227 | + """Remove FEEL Java-style comments (`//…\\n` and `/*…*/`) from `expr`. | |
| 228 | + | |
| 229 | + String-aware: characters inside double-quoted literals are preserved as-is, | |
| 230 | + so `"http://x"` and `"/* not a comment */"` are never mangled. | |
| 231 | + Block comments do not nest (per the FEEL spec). | |
| 232 | + """ | |
| 233 | + out: list[str] = [] | |
| 234 | + i = 0 | |
| 235 | + n = len(expr) | |
| 236 | + while i < n: | |
| 237 | + c = expr[i] | |
| 238 | + if c == '"': | |
| 239 | + # consume the whole quoted string verbatim | |
| 240 | + j = i + 1 | |
| 241 | + while j < n and expr[j] != '"': | |
| 242 | + if expr[j] == '\\': | |
| 243 | + j += 1 # skip escaped char | |
| 244 | + j += 1 | |
| 245 | + out.append(expr[i : j + 1]) | |
| 246 | + i = j + 1 | |
| 247 | + elif expr[i : i + 2] == "//": | |
| 248 | + # EOL comment — skip to (but not including) the newline | |
| 249 | + i += 2 | |
| 250 | + while i < n and expr[i] != '\n': | |
| 251 | + i += 1 | |
| 252 | + elif expr[i : i + 2] == "/*": | |
| 253 | + # block comment — skip to closing */ | |
| 254 | + i += 2 | |
| 255 | + while i < n and expr[i : i + 2] != "*/": | |
| 256 | + i += 1 | |
| 257 | + i += 2 # skip the closing */ | |
| 258 | + else: | |
| 259 | + out.append(c) | |
| 260 | + i += 1 | |
| 261 | + return "".join(out) | |
| 262 | + | |
| 263 | + | |
| 226 | 264 | def fits_slice_grammar(expression: str, input_names: frozenset[str] = frozenset()) -> bool: |
| 227 | 265 | """True if feel-core's core-language grammar can parse AND evaluate |
| 228 | 266 | `expression` against a context built from `input_names` (the case's |
| @@ -238,6 +276,9 @@ | ||
| 238 | 276 | keeping one feel-core cannot handle (a false positive would crash the |
| 239 | 277 | fixture test). The closed loop validates the rest — `cargo test -p feel-core` |
| 240 | 278 | asserts every kept case actually evaluates.""" |
| 279 | + # Strip Java-style comments before any other scan so comment text is never | |
| 280 | + # mistaken for free identifiers or operators. | |
| 281 | + expression = strip_comments(expression) | |
| 241 | 282 | # Blank out string literals so their contents never look like identifiers, |
| 242 | 283 | # operators or brackets. Temporal `@"…"` literals are in scope now (ADR-18); |
| 243 | 284 | # blanking the quoted part leaves a lone `@`, which the scans below ignore. |