← board

regex engine library

Motivation

re is not a niche import — it is in the standard vocabulary of real Python, and of real C/Pascal programs too. There is currently nothing to bind a nilpy re module to, so the engine is the substrate and comes first. Language-neutral by design, like every Track B library: one engine, consumed by nilpy's re ([[feature-nilpy-re-module]]) and directly usable from Pascal.

Surface (sketch)

A TRegex compiled-pattern object plus match results:

Feature subset songformatter actually needs, all 14 of its call sites surveyed:

Backtracking is the right shape here: patterns are short, subjects are single chord/lyric lines, and it keeps group capture and non-greedy semantics simple.

Gate

Track B: build with $(PXX_STABLE), never rebuild the compiler. make lib-test green with a test comparing the engine against expectations recorded from CPython's re for the surveyed patterns.

Update (2026-07-26) — landed

lib/rtl/regex.pas + test/lib_regex.pas, wired into make lib-test. 61 checks, all green, and every expectation cross-checked against CPython's re for the same pattern/subject pairs (a hand-written expectation WAS wrong: the songformatter chord class holds lower-case 'b' but not upper-case 'B', so G/B is correctly rejected — CPython agrees).

Two engineering notes worth keeping:

Not implemented, and reported by ReCompile as an error rather than mis-matched: lookaround, in-pattern backreferences, named groups, possessive quantifiers, unicode classes.

make lib-test has a PRE-EXISTING red unrelated to this work, now filed as [[feature-rtl-month-day-name-arrays]]: the lib_synapse step dies on undefined variable (ShortMonthNames). Reproduced on a clean tree with git stash -u. The regex step itself passes inside lib-test, before that point.

Log