diff --git a/lib/regex/regex.ww b/lib/regex/regex.ww index e3fc8d4c..247e8625 100644 --- a/lib/regex/regex.ww +++ b/lib/regex/regex.ww @@ -118,7 +118,8 @@ export fn finish(re: *regex) void = { }; // runtime (#27) — the port drops every Hare free(). export fn compile(expr: str) (regex | error | nomem) = { // Hare `let insts: []inst = [];` — a bare ww slice declaration - // zeroes the header (cf lib/shlex/shlex.ww:215). + // zeroes the header (cgen.c:9836 no-rhs multi-word composite + // zero-fill, symmetric in cgenstmt.ww). let insts: []inst; let charsets: []charset; // stays empty until the '[' fold let iter: strings.iterator = strings.iter(expr); @@ -131,6 +132,10 @@ export fn compile(expr: str) (regex | error | nomem) = { if (r_idx == 0 && next is rune && (next as rune) != '^') { // Bare append: ww append returns void; Hare's // `append(...)?` nomem propagation is filed #36. + // Hare appends the bare type name (`inst_skip`) as + // the void-variant value; in ww that resolves as a + // symbol ref (cf the alloc(T) rule), so void + // variants go through a typed let. let sk: inst_skip; let v: inst = sk; append(insts, v); @@ -149,17 +154,13 @@ export fn compile(expr: str) (regex | error | nomem) = { let v: inst = av; append(insts, v); }; - case ']': { // regex.ha:315-316 — literal outside a bracket - let v: inst = (r: inst_lit); - append(insts, v); - }; + case ']': // regex.ha:315-316 — literal outside a bracket + append(insts, (r: inst_lit)); case '\\', '^', '$', '[', '(', ')', '|', '{', '?', '*', '+': // fold-2a boundary: regex.ha:286-459 arms deferred. return "regex: metacharacter not yet ported": error; - case: { // regex.ha:462-463 - let v: inst = (r: inst_lit); - append(insts, v); - }; + case: // regex.ha:462-463 + append(insts, (r: inst_lit)); }; r_idx += 1; }; @@ -167,8 +168,7 @@ export fn compile(expr: str) (regex | error | nomem) = { // regex.ha:475-477. `$` appends true: inst_match — deferred, so // the guard can only see no-match today; kept verbatim. if (insts.len == 0 || !(insts[insts.len - 1] is inst_match)) { - let m: inst = (false: inst_match); - append(insts, m); + append(insts, (false: inst_match)); }; // regex.ha:479-484. The alternation fixup (ha:470-473) drops with // jump_idxs.