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 --- docs/mvzr-group-backtrack.md | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'docs') diff --git a/docs/mvzr-group-backtrack.md b/docs/mvzr-group-backtrack.md index d074af62..867336a3 100644 --- a/docs/mvzr-group-backtrack.md +++ b/docs/mvzr-group-backtrack.md @@ -62,3 +62,25 @@ string end at `e`, so a group ending in either can accept a cut the full string would not; a continuation-passing matcher (each repeat trying the rest of the whole pattern) would be the full fix. `hasAlt` returning false at the group's own `)` is worth fixing too. + +# mvzr: `$` before `|` is a bad pattern + +A second report, same trunk. `compile` refuses `$` anywhere but at the +very end of the pattern, so an anchored alternative must come last: + +```zig +std.debug.assert(mvzr.compile("zz|h$") != null); +std.debug.assert(mvzr.compile("h$|zz") == null); // expected a regex +std.debug.assert(mvzr.compile("(h$|zz)") == null); // likewise +``` + +The parser's check is `if (i + 1 < in.len) bad_string = true`. The +matcher already handles `.end` inside an alternative: `matchAlt` and +`matchGroup` hand `matchPattern` each alternative as its own slice, and +`.end` returns an empty rest, which ends that slice. So `$` can stand +before `|` or `)` as well as last; pardes's patch: + +```zig +'$' => { + if (i + 1 < in.len and in[i + 1] != '|' and in[i + 1] != ')') { +``` -- cgit v1.3