diff options
| author | Gabriel Schneider <[email protected]> | 2026-09-29 01:41:06 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-10-01 00:12:15 -0300 |
| commit | 0423e315dfeaa5af48d2186a8f0997e1904f3da9 (patch) | |
| tree | 39a222618da1eb764653db16a31330ca85e09770 /docs | |
| parent | 0493ed9c6e2af1c16b40a685efdb67881ac87570 (diff) | |
| download | pardes-0423e315dfeaa5af48d2186a8f0997e1904f3da9.tar.gz pardes-0423e315dfeaa5af48d2186a8f0997e1904f3da9.zip | |
$ 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 <[email protected]>
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/mvzr-group-backtrack.md | 22 |
1 files changed, 22 insertions, 0 deletions
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] != ')') { +``` |
