From 0423e315dfeaa5af48d2186a8f0997e1904f3da9 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Tue, 29 Sep 2026 01:41:06 -0300 Subject: $ may end any alternative in a pattern, not only the last mvzr refuses $ anywhere but at the very end, so /h$|zz/ and Edit ,x/r$|pi/ were bad patterns while /zz|h$/ worked. Its matcher already ends an alternative at .end, so a build-time patch, anchor-checked like the group one, lets $ stand before | and ). The upstream report is in docs/mvzr-group-backtrack.md. Co-Authored-By: Claude Opus 5.5 --- build.zig | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'build.zig') diff --git a/build.zig b/build.zig index e63b7f4b..fb17afd8 100644 --- a/build.zig +++ b/build.zig @@ -500,7 +500,24 @@ pub fn build(b: *std.Build) void { \\ ; if (std.mem.count(u8, budgeted, group_anchor) != 1) @panic("mvzr's matchGroup changed: redo its group backtracking in build.zig"); - const patched = std.mem.replaceOwned(u8, b.allocator, budgeted, group_anchor, group_backoff) catch @panic("OOM"); + const backed = std.mem.replaceOwned(u8, b.allocator, budgeted, group_anchor, group_backoff) catch @panic("OOM"); + // `$` is refused anywhere but last, so `h$|zz` was a bad pattern + // while `zz|h$` was fine. An alternative or a group ends at `|` and + // `)`, and the matcher's `.end` ends the alternative it is in, so + // `$` may stand before either (docs/mvzr-group-backtrack.md). + const end_anchor = + \\ '$' => { + \\ if (i + 1 < in.len) { + \\ + ; + const end_before_alt = + \\ '$' => { + \\ // pardes's patch (its build.zig): `$` may end an alternative. + \\ if (i + 1 < in.len and in[i + 1] != '|' and in[i + 1] != ')') { + \\ + ; + if (std.mem.count(u8, backed, end_anchor) != 1) @panic("mvzr's parser changed: redo its `$` before `|` in build.zig"); + const patched = std.mem.replaceOwned(u8, b.allocator, backed, end_anchor, end_before_alt) catch @panic("OOM"); break :mvzr b.createModule(.{ .root_source_file = b.addWriteFiles().add("mvzr.zig", patched), .target = target, .optimize = optimize }); }; -- cgit v1.3