Skip to content

[TS] Support linear RegExp literals in test and match - #535

Merged
CaelmBleidd merged 3 commits into
mainfrom
caelmbleidd/regexp-literal-test-match
Oct 16, 2026
Merged

CaelmBleidd merged 3 commits into
mainfrom
caelmbleidd/regexp-literal-test-match

Conversation

@CaelmBleidd

Copy link
Copy Markdown
Member

DateUtils cannot reach its date-math parser because every intrinsic RegExp literal currently stops execution. Add core runtime semantics for a bounded linear subset used by its actual pattern and simpler date-fns token checks. These operations are available with EMPTY and FROZEN model selections and either residual-call policy.

The supported grammar is UTF-16 literals, finite character classes/ranges, ASCII \d/\w, capturing/noncapturing groups, start/end anchors, greedy atom +, and one optional fixed trailing group. A repeated atom must have a disjoint following atom, so it cannot require backtracking; variable-width patterns require ^. Flags, alternation, lookaround, backreferences, unsupported quantifiers, coercion and custom exec remain explicit limitations. The syntax budget is 256 source code units / 64 atoms.

Build Bool/ITE terms directly. Each greedy run scans the existing backing bound once; fixed unanchored patterns use a leftmost-match ITE chain. There is no bound-squared start × repetition expansion or interpreted regex loop. Match captures reuse the existing range-copy operation, with a fresh mutable result array, undefined absent captures, and index/input/groups metadata. Without /m, $ requires the absolute end, including rejecting a final newline.

Small hooks retain intrinsic regex identity across forks and handle lastIndex/properties without relying on missing structural SDK declarations. A custom test method follows ordinary dispatch; a custom exec callback stops rather than being bypassed. No frontend, SDK, dependency pin or model-catalog changes are needed.

Validation: 16 focused tests passed (7 RegExp test groups and 9 existing runtime-limitation tests), zero skips. They include the real DateUtils pattern with symbolic success/failure/optional captures, all four model/fallback profiles, default backing bound 1000, UTF-16 surrogate units, final LF/CR/CRLF/U+2028/U+2029, leftmost matching, fresh arrays, overrides and unsupported boundaries. Every generated witness in the replay test passes the original source in Node. Restoring the previous literal-allocation limitation makes the DateUtils source regression fail at its unexpected-unsupported-path assertion. CI-style :usvm-ts:detektMain :usvm-ts:detektTest passed with zero new findings.

This is deliberately partial RegExp support. Complex date-fns parseISO/format expressions, flags and dynamically constructed patterns remain outside it. The full 200-class rerun will measure diagnostic applicability on the combined fixes; these focused checks do not claim full-cohort coverage or performance results.

@CaelmBleidd
CaelmBleidd force-pushed the caelmbleidd/regexp-literal-test-match branch from 8df3d31 to 0bfb1cc Compare October 16, 2026 13:51
@CaelmBleidd
CaelmBleidd merged commit 3cb65d0 into main Oct 16, 2026
7 checks passed
@CaelmBleidd
CaelmBleidd deleted the caelmbleidd/regexp-literal-test-match branch October 16, 2026 15:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants