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:
@@ -23,6 +23,7 @@ package regex;
|
|||||||
|
|
||||||
import regex;
|
import regex;
|
||||||
import os;
|
import os;
|
||||||
|
import strings;
|
||||||
|
|
||||||
let signalled: i32 = 0;
|
let signalled: i32 = 0;
|
||||||
fn fail() void = { os.exit(signalled + 10); };
|
fn fail() void = { os.exit(signalled + 10); };
|
||||||
@@ -244,12 +245,30 @@ fn fail() void = { os.exit(signalled + 10); };
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
// Any deferred metacharacter is a LOUD error — pins the fold-2a
|
// Every deferred metacharacter is a LOUD error carrying the exact
|
||||||
// boundary so the fold that ports '*' consciously deletes this row.
|
// 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 = {
|
@test fn compile_metachar_loud() void = {
|
||||||
match (regex.compile("a*")) {
|
let pats: [11]str = [
|
||||||
case let e: regex.error => { if ((e: str).len == 0) { fail(); }; };
|
"a\\", "^a", "a$", "a[", "a(", "a)",
|
||||||
case => fail();
|
"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;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user