summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-09-29 01:41:06 -0300
committerGabriel Schneider <[email protected]>2026-10-01 00:12:15 -0300
commit0423e315dfeaa5af48d2186a8f0997e1904f3da9 (patch)
tree39a222618da1eb764653db16a31330ca85e09770 /src
parent0493ed9c6e2af1c16b40a685efdb67881ac87570 (diff)
downloadpardes-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 'src')
-rw-r--r--src/regexp.zig17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/regexp.zig b/src/regexp.zig
index 97e3dc91..64e1d75a 100644
--- a/src/regexp.zig
+++ b/src/regexp.zig
@@ -258,3 +258,20 @@ test "a repeat inside a group gives back to what follows the group" {
try std.testing.expectEqual(c.end, m.end);
}
}
+
+test "`$` may end any alternative, not only the last" {
+ const Case = struct { pat: []const u8, text: []const u8, start: usize, end: usize };
+ for ([_]Case{
+ .{ .pat = "h$|zz", .text = "xh", .start = 1, .end = 2 },
+ .{ .pat = "zz|h$", .text = "xh", .start = 1, .end = 2 },
+ .{ .pat = "h$|zz", .text = "hx zz", .start = 3, .end = 5 },
+ .{ .pat = "(h$|zz)", .text = "xh", .start = 1, .end = 2 },
+ }) |c| {
+ var rx = try Regex.compile(c.pat);
+ const m = (try rx.find(c.text, 0, c.text.len, c.text.len)).?;
+ try std.testing.expectEqual(c.start, m.start);
+ try std.testing.expectEqual(c.end, m.end);
+ }
+ var only = try Regex.compile("h$|zz");
+ try std.testing.expectEqual(null, try only.find("hx", 0, 2, 2));
+}