also looking at this
Migrate to zig 0.16
#5
13 files
+222
-239
Review threads live on the whole diff, not on one commit, so none are shown here - a thread's line means something in the branch's final form, and painting it into an intermediate step would put it on code it is not about.
| @@ -4,20 +4,16 @@ const ErrorContext = .ErrorContext; | ||
| 4 | 4 | const ErrorHelper = .ErrorHelper; |
| 5 | 5 | const RegexError = .RegexError; |
| 6 | 6 | |
| 7 | pub fn main() !void { | |
| 8 | var gpa = std.heap.GeneralPurposeAllocator(.{}){}; | |
| 9 | defer _ = gpa.deinit(); | |
| 10 | const allocator = gpa.allocator(); | |
| 11 | ||
| 7 | pub fn main(init: std.process.Init) !void { | |
| 12 | 8 | std.debug.print("\n=== Regex Error Handling Examples ===\n\n", .{}); |
| 13 | 9 | |
| 14 | 10 | // Example 1: Invalid patterns with helpful error messages |
| 15 | 11 | const invalid_patterns = [_][]const u8{ |
| 16 | "abc(def", // Unmatched parenthesis | |
| 17 | "abc[def", // Unmatched bracket | |
| 18 | "abc+(", // Invalid quantifier usage | |
| 19 | "abc\\q", // Invalid escape sequence | |
| 20 | "[z-a]", // Invalid character range | |
| 12 | "abc(def", // Unmatched parenthesis | |
| 13 | "abc[def", // Unmatched bracket | |
| 14 | "abc+(", // Invalid quantifier usage | |
| 15 | "abc\\q", // Invalid escape sequence | |
| 16 | "[z-a]", // Invalid character range | |
| 21 | 17 | "(a(b(c(d(e(f(g(h(i(j(k(l(m(n(o(p(q", // Too many nested groups |
| 22 | 18 | }; |
| 23 | 19 | |
| @@ -26,7 +22,7 @@ pub fn main() !void { | ||
| 26 | 22 | std.debug.print("Testing pattern: \"{s}\"\n", .{pattern}); |
| 27 | 23 | std.debug.print("───────────────────────────────────────────────\n", .{}); |
| 28 | 24 | |
| 29 | if (Regex.compile(allocator, pattern)) |regex_value| { | |
| 25 | if (Regex.compile(init.gpa, pattern)) |regex_value| { | |
| 30 | 26 | var regex = regex_value; |
| 31 | 27 | defer regex.deinit(); |
| 32 | 28 | std.debug.print("✓ Pattern compiled successfully (unexpected)\n\n", .{}); |
| @@ -53,7 +49,7 @@ pub fn main() !void { | ||
| 53 | 49 | const user_pattern = "hello|world"; |
| 54 | 50 | std.debug.print("User provided pattern: \"{s}\"\n", .{user_pattern}); |
| 55 | 51 | |
| 56 | if (Regex.compile(allocator, user_pattern)) |regex_value| { | |
| 52 | if (Regex.compile(init.gpa, user_pattern)) |regex_value| { | |
| 57 | 53 | var regex = regex_value; |
| 58 | 54 | defer regex.deinit(); |
| 59 | 55 | std.debug.print("✓ Pattern compiled successfully\n", .{}); |
| @@ -84,7 +80,7 @@ pub fn main() !void { | ||
| 84 | 80 | const problematic_pattern = "abc[def"; |
| 85 | 81 | std.debug.print("Problematic pattern: \"{s}\"\n", .{problematic_pattern}); |
| 86 | 82 | |
| 87 | if (Regex.compile(allocator, problematic_pattern)) |regex_value| { | |
| 83 | if (Regex.compile(init.gpa, problematic_pattern)) |regex_value| { | |
| 88 | 84 | var regex = regex_value; |
| 89 | 85 | regex.deinit(); |
| 90 | 86 | } else |err| { |
| @@ -95,7 +91,7 @@ pub fn main() !void { | ||
| 95 | 91 | const fixed_pattern = "abc[def]"; |
| 96 | 92 | std.debug.print("Fixed pattern: \"{s}\"\n", .{fixed_pattern}); |
| 97 | 93 | |
| 98 | if (Regex.compile(allocator, fixed_pattern)) |regex_value| { | |
| 94 | if (Regex.compile(init.gpa, fixed_pattern)) |regex_value| { | |
| 99 | 95 | var regex = regex_value; |
| 100 | 96 | defer regex.deinit(); |
| 101 | 97 | std.debug.print("✓ Fixed pattern compiles successfully!\n", .{}); |
| @@ -119,7 +115,7 @@ pub fn main() !void { | ||
| 119 | 115 | |
| 120 | 116 | for (patterns_to_validate) |pattern| { |
| 121 | 117 | std.debug.print("Validating: \"{s}\" ... ", .{pattern}); |
| 122 | if (Regex.compile(allocator, pattern)) |regex_value| { | |
| 118 | if (Regex.compile(init.gpa, pattern)) |regex_value| { | |
| 123 | 119 | var regex = regex_value; |
| 124 | 120 | regex.deinit(); |
| 125 | 121 | std.debug.print("✓ Valid\n", .{}); |