Skip to content

ERE parity: escapes, POSIX classes, {n,m} intervals, re_replace + builtin-shaped compat layer#4

Merged
InauguralPhysicist merged 1 commit into
mainfrom
ere-parity
Jul 2, 2026
Merged

ERE parity: escapes, POSIX classes, {n,m} intervals, re_replace + builtin-shaped compat layer#4
InauguralPhysicist merged 1 commit into
mainfrom
ere-parity

Conversation

@InauguralPhysicist

Copy link
Copy Markdown
Contributor

Closes the gaps between the Pike-VM engine and the libc-backed regex_* builtins so lib/regex_compat.eigs can drop in for them in EigenScript's freestanding (EigenOS) profile — the regex disposition in EigenScript's docs/FREESTANDING.md ledger.

What's in

  • S6 — escapes + POSIX classes: \.-style literal escapes, \w \W \s \S, 12 [[:name:]] classes composable with ranges/negation. Glibc-parity trap preserved deliberately: \d is a literal d in ERE (verified against the builtin oracle).
  • S7 — {n} {n,} {n,m} intervals (with lazy ? variants): pure parser desugaring to existing AST forms — no new VM ops, the O(n·m) guarantee is untouched. Shared-subtree repetition reproduces glibc's last-repetition-wins capture semantics (^(a|b){2}$ on "ab" captures "b", oracle-verified). Invalid specs are parse errors like glibc; bounds cap at 255.
  • S8 — re_replace (literal replacement, builtin-identical zero-width behavior: x* over abc-a-b-c-) and lib/regex_compat.eigs: regex_match / regex_find / regex_replace with the builtins' exact names, shapes, and quirks (group-list truncation at first non-participating group, 16-entry cap, bad-pattern → []/input).

Verification

  • Suite 347/347 green on v0.23.0 (220 existing unchanged + 127 new), including a 42-check differential running shim-vs-builtin over shared inputs with the libc builtins as the oracle.
  • Extra adversarial differentials (nested intervals with captures, negated POSIX unions, {0,0}) all agree with the oracle.

Documented divergences (in the compat header)

POSIX leftmost-longest vs Pike-VM leftmost-first (a|ab differs); no \b/\B (needs text access in the VM's epsilon-closure — deferred); the builtins' NOTBOL ^ re-anchoring quirk in find/replace is not replicated.

🤖 Generated with Claude Code

…place + builtin-shaped compat layer (S8)

Closes the four gaps between the Pike-VM engine and EigenScript's
libc-backed regex builtins, so lib/regex_compat.eigs can drop in for
regex_match/regex_find/regex_replace in the freestanding (EigenOS)
profile where libc regcomp is gone:

- parser: backslash escapes (\. \* \\ etc. literal; \w \W \s \S
  classes; \d stays a literal 'd' — glibc ERE parity, verified against
  the builtin oracle; trailing backslash errors)
- parser: POSIX [[:alpha:]]-style classes (12 names + [:word:]),
  composable with ranges and negation; unknown names error
- parser: {n} {n,} {n,m} intervals with lazy '?' variants, desugared to
  existing AST forms (no new VM ops). The repeated subtree is shared —
  safe because the compiler never mutates AST nodes — which reproduces
  glibc's last-repetition-wins capture semantics. Invalid/unclosed
  specs are parse errors like glibc; bounds cap at 255.
- lib/regex.eigs: re_replace (literal replacement, zero-width matches
  pass one char through — byte-matches the builtin's "-a-b-c-" shape)
- lib/regex_compat.eigs (new): regex_match/regex_find/regex_replace
  with the builtins' exact names, arg shapes, substring returns, and
  quirks (group list truncates at first non-participating group, caps
  at 16; bad pattern → []/input). Known divergences documented in the
  header: POSIX leftmost-longest vs Pike-VM leftmost-first, no \b.

Tests: S6 (40) + S7 (39) + S8 (48, including a 42-check differential
suite running shim-vs-builtin over shared inputs with the libc builtins
as the oracle). Suite 347/347 green on EigenScript v0.23.0.

Docs: README + CLAUDE.md feature/status/layout refresh; stale EIGS_REF
note corrected to v0.23.0.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.

1 participant