summaryrefslogtreecommitdiff
path: root/src/regexp.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-05 00:03:55 -0300
committerGabriel Schneider <[email protected]>2026-11-05 01:16:28 -0300
commita92951b11ab3aa2cdf759b3b743f8af006c21b95 (patch)
treeb63d45772ea2053f0feb796e5893b81f88a1bf0c /src/regexp.zig
parentbbb4362a46de8e8d10a6a937e61ccc8f3a0ba4b3 (diff)
downloadpardes-a92951b11ab3aa2cdf759b3b743f8af006c21b95.tar.gz
pardes-a92951b11ab3aa2cdf759b3b743f8af006c21b95.zip
regexp, sam_edit, ninep/addr: a pattern's compile error is told by Regex.message(err), which replaces the five e_ constants and the two switches that mapped errors onto them
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
Diffstat (limited to 'src/regexp.zig')
-rw-r--r--src/regexp.zig19
1 files changed, 13 insertions, 6 deletions
diff --git a/src/regexp.zig b/src/regexp.zig
index 6c858dea..7bcbceff 100644
--- a/src/regexp.zig
+++ b/src/regexp.zig
@@ -28,7 +28,7 @@ const mvzr = @import("mvzr");
/// one.
/// mvzr's own `Regex` holds 64 operations, some 64 pattern characters; a
/// search pattern is often longer. Past these a pattern is refused naming
-/// the limit (`e_long`).
+/// the limit (`message`).
pub const max_ops = 512;
const Compiled = mvzr.SizedRegex(max_ops, 64);
@@ -62,11 +62,18 @@ pub const Regex = struct {
/// is ten times slower at it, about two seconds).
pub const budget: u64 = 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";
- pub const e_wide = std.fmt.comptimePrint("bad regular expression: a range of runes wider than {d} in [...] is not supported", .{max_range});
- pub const e_negated = "bad regular expression: a [^...] with non-ASCII runes is not supported (mvzr's classes hold bytes)";
- pub const e_mixed = "bad regular expression: an alternation anchors every branch with ^ or none (^a|^b, not ^a|b)";
+ /// What a pattern that does not compile is told; `Bad`'s words are
+ /// its caller's (which command, which address).
+ pub fn message(err: Error) []const u8 {
+ return switch (err) {
+ error.TooLong => std.fmt.comptimePrint("bad regular expression: longer than mvzr's {d} operations (about {d} pattern characters)", .{ max_ops, max_ops }),
+ error.Anchor => "bad regular expression: in a pattern with \\n, ^ can only come first and $ only just before a \\n",
+ error.WideRange => std.fmt.comptimePrint("bad regular expression: a range of runes wider than {d} in [...] is not supported", .{max_range}),
+ error.NegatedRunes => "bad regular expression: a [^...] with non-ASCII runes is not supported (mvzr's classes hold bytes)",
+ error.Mixed => "bad regular expression: an alternation anchors every branch with ^ or none (^a|^b, not ^a|b)",
+ error.Bad => "bad regular expression",
+ };
+ }
/// The most runes a non-ASCII range in a class is spelled out as.
pub const max_range = 256;