lib/regex: fold-2b tranche D — test/find (the exec surface)
Port of test (ref/hare/regex/regex.ha:901-904) and find (ha:907-918) — the exported exec surface over tranche C's search. fold 2b is COMPLETE: compile → test/find runs end to end on the 2a literal programs. Both are |success|=2 `?` sites in Hare (`search(...)?` over (void | []capture | nomem)); ww's `?` is gated to single-success unions (the C6 interim), so each spells the propagation as the explicit 3-arm match harec lowers `?` into (ref/harec/src/check.c: 2780) — the ratified D13 spelling, on task #14's acceptance list for reversion when subset-union `?` lands. find's no-match `return [];` (ha:916) binds a zero header first (#25/#31 ruling) — a valid empty result the caller still result_frees. io::handle args are the landed memio→io cast (&strm.vt); import memio added. PD1 probed first (scratch/pd1.ww): []capture values returning through (result | nomem) — the nominal-alias member — plus the (bool | nomem) round-trip; build/run/byte-id green at base, so no new compiler surface was crossed. regex_test: +2 @test fns (signalled 23-24). test_matches = 8-row tcase table (the six search-table inputs → true, thread-drain and EOF-mid-pattern → false). find_cases = 8-row fcase table: the six match rows reuse the search table's root-capture expectations (all four indices + content), the two no-match rows pin the empty result; result_free on every row, matched or not. Every fcase row also cross-pins test/find agreement (test(re, s) == find(re, s) matched), so an arm-swap in either D13 match is caught by the other surface. Both drivers run the fixture exit 0; w6c vs w6c_ww on the regenerated combined byte-identical (FC0).
This commit is contained in:
@@ -4,11 +4,12 @@
|
||||
// tranche A = the thread-machine scaffolding (thread/newmatch types,
|
||||
// result_free, strerror); fold 2b tranche B = the engine
|
||||
// (delete_thread/is_consuming_inst/add_thread/run_thread); fold 2b
|
||||
// tranche C = search, the first end-to-end match. Every other
|
||||
// metacharacter arm and the exec surface (test/find on the C6
|
||||
// multi-success `?` gate, tranche D; replace) are DEFERRED behind
|
||||
// compiler fixes — probed pre-port, pA*/pB*/PB*/PC* probes. They
|
||||
// land with those fixes.
|
||||
// tranche C = search, the first end-to-end match; fold 2b tranche D
|
||||
// = the exec surface (test/find — the D13 explicit-match spelling of
|
||||
// Hare's multi-success `?`, ww-core #14). Every other metacharacter
|
||||
// arm (and replace/findall) is DEFERRED behind compiler fixes —
|
||||
// probed pre-port, pA*/pB*/PB*/PC*/PD* probes. They land with those
|
||||
// fixes.
|
||||
//
|
||||
// One fold-1 construct is held back behind a filed compiler/fidelity
|
||||
// gap (see the charclass_map site below):
|
||||
@@ -20,6 +21,7 @@ package regex;
|
||||
|
||||
import bufio;
|
||||
import io;
|
||||
import memio;
|
||||
import strings;
|
||||
import types;
|
||||
import encoding.utf8;
|
||||
@@ -597,6 +599,49 @@ fn search(
|
||||
};
|
||||
};
|
||||
|
||||
// Returns whether or not a [[regex]] matches any part of a given
|
||||
// string.
|
||||
//
|
||||
// ref/hare/regex/regex.ha:900-904. Hare's io::handle arg `&strm` is
|
||||
// the landed memio→io cast `&strm.vt`. Hare unwraps with
|
||||
// `search(...)? is []capture` — a |success|=2 union; ww's `?` is
|
||||
// gated to single-success unions (the C6 interim, ww-core #14), so
|
||||
// the propagation is spelled as the explicit match harec lowers `?`
|
||||
// into (ref/harec/src/check.c:2780) — the ratified D13 spelling,
|
||||
// reverts with #14.
|
||||
export fn test(re: *regex, string: str) (bool | nomem) = {
|
||||
let strm: memio.stream = memio.fixed(strings.toutf8(string));
|
||||
let r: (void | []capture | nomem) =
|
||||
search(re, string, &strm.vt, false);
|
||||
match (r) {
|
||||
case let m: []capture => return true;
|
||||
case void => return false;
|
||||
case let n: nomem => return n;
|
||||
};
|
||||
};
|
||||
|
||||
// Attempts to match a [[regex]] against a string and returns the
|
||||
// longest leftmost match as a [[result]]. The caller must free the
|
||||
// return value with [[result_free]].
|
||||
//
|
||||
// ref/hare/regex/regex.ha:907-918. Same explicit `?` lowering as
|
||||
// test() (D13, ww-core #14); the no-match `return [];` (ha:916)
|
||||
// binds a zero header first (#25/#31 ruling) — a valid empty result
|
||||
// the caller still result_frees.
|
||||
export fn find(re: *regex, string: str) (result | nomem) = {
|
||||
let strm: memio.stream = memio.fixed(strings.toutf8(string));
|
||||
let r: (void | []capture | nomem) =
|
||||
search(re, string, &strm.vt, true);
|
||||
match (r) {
|
||||
case let m: []capture => return m;
|
||||
case void => {
|
||||
let empty: []capture;
|
||||
return empty;
|
||||
};
|
||||
case let n: nomem => return n;
|
||||
};
|
||||
};
|
||||
|
||||
// Frees a [[result]].
|
||||
//
|
||||
// ref/hare/regex/regex.ha:1113-1116, verbatim — the free() builtin is
|
||||
|
||||
Reference in New Issue
Block a user