◀ THE FOLD0ROOT.AI // WORLD II · BOSS · THE RAID◆ .dlw.fold
THE FOLD / BOSS / THE RAID / A REGEX MEETING NESTING

A REGEX MEETING NESTING

the error surfaces four frames from its cause
1 WHAT IT IS · WHAT IT DOES · FACT OR FICTION
Five bugs in one build, every one a regex meeting a nested structure. A parse tree nests; a regular expression does not. And the reason it kept costing time is not that the patterns were wrong — it is where the wrongness surfaced: an index error several call frames away, naming neither the arrays nor the intrinsics that caused it.

LIT verified live. A character class of [^()]* stops at the first inner parenthesis. A greedy (.*) collapses 6 separate calls into 1 match. A depth-counting scanner recovers all 6, every one balanced. Feed the single greedy match to a consumer expecting six and it fails with “IndexError: list index out of range” — a message naming neither arrays, nor intrinsics, nor the pattern.
2 HOW IT WAS WEAVED · AI + HUMAN
David (human) listed all five and found the shape they share: “every one is a REGEX MEETING NESTING. the parse tree is nested; regexes are not. each fix replaced a pattern with a scanner, and the one still broken is the one still using a pattern.” Then the part that is actually the lesson: “the error surfaced as an index error four call frames away from its cause, every single time. a wrong pattern does not report a wrong pattern.”

AVAN (AI) must be precise about one figure. His bug 3 reports a greedy match holding 7 open parens and 2 closed; the six-call line reconstructed here produces a balanced capture, 11 and 11. That imbalance depends on the exact line his build hit, which this page does not have. The collapse is reproduced — six calls into one — and the imbalance is his, cited and not re-derived.
3 ONE DIMENSION
Three matchers on the same nested line.
4 TWO DIMENSIONS · INTERACTIVE
Nest the argument deeper and watch each matcher fail.
5 THREE DIMENSIONS + AVAN’S INVERSE
The green forward object: a cause here, a symptom over there.
AVAN’s addition (the inverse-companion): the forward reading is “replace patterns with scanners.” The inverse is that the regex was the right tool for the first four cases and stopped being right without announcing it. Flat matching is faster to write, faster to read, and correct until the input nests — and every one of these bugs began as working code on inputs that happened to be flat. Read backwards, the failure is not a bad choice of tool but a tool outliving the assumption it was chosen under, which no amount of care at the moment of writing would have caught.
LIT a character class of [^()]* stops at the first inner parenthesis, a greedy (.*) collapses 6 separate calls into 1 match, and a depth-counting scanner recovers all 6 every one balanced; feed the single greedy match to a consumer expecting six and it fails with IndexError list index out of range - a message naming neither arrays, nor intrinsics, nor the pattern

FIG David listed all five and found the shape they share: 'every one is a REGEX MEETING NESTING. the parse tree is nested; regexes are not. each fix replaced a pattern with a scanner, and the one still broken is the one still using a pattern.' Then the actual lesson: 'the error surfaced as an index error four call frames away from its cause, every single time. a wrong pattern does not report a wrong pattern.' AVAN must be precise about one figure: his bug 3 reports a greedy match holding 7 open parens and 2 closed, while the six-call line reconstructed here produces a BALANCED capture, 11 and 11. That imbalance depends on the exact line his build hit, which this page does not have. The COLLAPSE is reproduced; the imbalance is his, cited and not re-derived.
◆ sealed .dlw.fold → folded to ROOT_0 · a sphere of THE RAID · David Lee Wise (ROOT0), with AVAN