lib/regex: pin exact loud-boundary text across all 11 deferred metachars (fold-2a review)

The loud-arm row asserted only a non-empty error on "a*" — a
half-ported arm returning any other error text, or another metachar
falling to the literal default, would have passed. Table over one
pattern per deferred arm ('^' leading, so the r_idx==0 skip gate
composes with the loud arm) compared against the exact boundary
text via strings.compare.
This commit is contained in:
2026-06-04 05:45:52 +09:00
parent de7dc36da3
commit 64f6cc90f2

View File

@@ -23,6 +23,7 @@ package regex;
import regex;
import os;
import strings;
let signalled: i32 = 0;
fn fail() void = { os.exit(signalled + 10); };
@@ -244,13 +245,31 @@ fn fail() void = { os.exit(signalled + 10); };
};
};
// Any deferred metacharacter is a LOUD error — pins the fold-2a
// boundary so the fold that ports '*' consciously deletes this row.
// Every deferred metacharacter is a LOUD error carrying the exact
// fold-boundary text — falling through to the literal default would
// silently compile a wrong program, and any OTHER error text would
// mean an arm was half-ported. One pattern per deferred arm so the
// fold that ports an arm consciously deletes its row. '^' leads its
// pattern: the r_idx==0 skip gate (regex.ha:261) must compose with
// the loud arm, not bypass it.
@test fn compile_metachar_loud() void = {
match (regex.compile("a*")) {
case let e: regex.error => { if ((e: str).len == 0) { fail(); }; };
let pats: [11]str = [
"a\\", "^a", "a$", "a[", "a(", "a)",
"a|", "a{", "a?", "a*", "a+",
];
let i: i32 = 0;
for (i < len(pats)) {
match (regex.compile(pats[i])) {
case let e: regex.error => {
if (strings.compare((e: str),
"regex: metacharacter not yet ported") != 0) {
fail();
};
};
case => fail();
};
i += 1;
};
};
export fn main() i32 = {