summaryrefslogtreecommitdiff
path: root/src/regexp.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-10-22 09:50:43 -0300
committerGabriel Schneider <[email protected]>2026-10-22 10:03:24 -0300
commita8b457a306a4442975210bcac3f04b56513c61c3 (patch)
tree6e2026ecb15da2fb919a0202f5d8b38e3b36a595 /src/regexp.zig
parenta8a1499bdffffc5b6919e24ec957e92fabaf003b (diff)
parent7e9d2c4169245072265b483ffaa6aa05f23f08d3 (diff)
downloadpardes-a8b457a306a4442975210bcac3f04b56513c61c3.tar.gz
pardes-a8b457a306a4442975210bcac3f04b56513c61c3.zip
Merge: Def/Refs, the diff viewer, Helix n/N, Callstack, Zig 0.17, Window mode and the terminal cwd fix onto 0.24
The docs keep both sides: 0.24's Ctrl-i fallbacks and typed ls with this line's Window mode, raw Esc and Helix n/N wording. The CHANGELOG's unreleased entries go above 0.24, Def/Refs and the context rows among them. cheatsheet-a4.pdf rendered again; .scratch/ ignored. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Diffstat (limited to 'src/regexp.zig')
-rw-r--r--src/regexp.zig12
1 files changed, 6 insertions, 6 deletions
diff --git a/src/regexp.zig b/src/regexp.zig
index 86132f60..4cbca57e 100644
--- a/src/regexp.zig
+++ b/src/regexp.zig
@@ -58,7 +58,7 @@ pub const Regex = struct {
/// Timed on this machine's ReleaseSafe build: 10M steps of the worst
/// patterns take 45-80 ms, and a Debug build is ten times slower.
- pub const budget: u64 = if (builtin.mode == .Debug) 4_000_000 else 32_000_000;
+ pub const budget: u64 = if (builtin.mode == .debug) 4_000_000 else 32_000_000;
pub const e_long = std.fmt.comptimePrint("bad regular expression: longer than mvzr's {d} operations (about {d} pattern characters)", .{ max_ops, max_ops });
pub const e_anchor = "bad regular expression: in a pattern with \\n, ^ can only come first and $ only just before a \\n";
@@ -503,10 +503,10 @@ test "a class with non-ASCII runes matches those runes: [éa-z], a range of them
}
test "a pattern past 64 characters compiles, and one past the limit says so" {
- var long = try Regex.compile("a" ** 200);
- const text = "x" ++ "a" ** 200 ++ "\n";
+ var long = try Regex.compile(&@as([200]u8, @splat('a')));
+ const text = "x" ++ &@as([200]u8, @splat('a')) ++ "\n";
try std.testing.expectEqual(@as(usize, 1), (try long.find(text, 0, text.len, text.len)).?.start);
- try std.testing.expectError(error.TooLong, Regex.compile("a" ** (max_ops + 8)));
+ try std.testing.expectError(error.TooLong, Regex.compile(&@as([max_ops + 8]u8, @splat('a'))));
try std.testing.expectError(error.Bad, Regex.compile("a[b"));
}
@@ -546,13 +546,13 @@ test "a search that would backtrack without end runs out of budget, promptly" {
// As long a chain as mvzr compiles, over runs one `a` short of it: 2^20
// steps from every start.
for (0..line.len / 20) |i| line[i * 20 + 19] = 'b';
- var chain = try Regex.compile("a?" ** 20 ++ "a" ** 20);
+ var chain = try Regex.compile(std.mem.asBytes(&@as([20][2]u8, @splat("a?".*))) ++ &@as([20]u8, @splat('a')));
try std.testing.expectError(error.TooSlow, chain.find(&line, 0, line.len, line.len));
}
test "the match is the leftmost, however long the line" {
// A window cut into the identifier would find `x... =` from its middle.
- const text = "let " ++ "x" ** 100 ++ " = 1";
+ const text = "let " ++ &@as([100]u8, @splat('x')) ++ " = 1";
var assign = try Regex.compile("\\s*(\\w+)\\s*=");
const m = (try assign.find(text, 0, text.len, text.len)).?;
try std.testing.expectEqual(@as(usize, 3), m.start);