ReviewOS

also looking at this

zig-utils/zig-regex

Port to latest zig-master

#2
Closed armagidon-exception wants to merge main into main
53 files +1149 -1017
tests/lazy_quantifiers.zigmodified+23-23
Changes to tests/lazy_quantifiers.zig
@@ -5,7 +5,7 @@ const Regex = @import("regex").Regex;
55
66test "lazy star: a*? matches minimal" {
77 const allocator = std.testing.allocator;
8 var regex = try Regex.compile(allocator, "a*?b");
8 var regex = try Regex.compile(allocator, std.testing.io, "a*?b");
99 defer regex.deinit();
1010
1111 // Greedy would match "aaab", lazy should match "b"
@@ -22,7 +22,7 @@ test "lazy star vs greedy star" {
2222 const allocator = std.testing.allocator;
2323
2424 // Greedy star
25 var greedy = try Regex.compile(allocator, "a*b");
25 var greedy = try Regex.compile(allocator, std.testing.io, "a*b");
2626 defer greedy.deinit();
2727
2828 if (try greedy.find("aaab")) |match| {
@@ -35,7 +35,7 @@ test "lazy star vs greedy star" {
3535 }
3636
3737 // Lazy star
38 var lazy = try Regex.compile(allocator, "a*?b");
38 var lazy = try Regex.compile(allocator, std.testing.io, "a*?b");
3939 defer lazy.deinit();
4040
4141 if (try lazy.find("aaab")) |match| {
@@ -50,7 +50,7 @@ test "lazy star vs greedy star" {
5050
5151test "lazy plus: a+? matches minimal (at least one)" {
5252 const allocator = std.testing.allocator;
53 var regex = try Regex.compile(allocator, "a+?b");
53 var regex = try Regex.compile(allocator, std.testing.io, "a+?b");
5454 defer regex.deinit();
5555
5656 // Lazy plus must match at least one 'a'
@@ -67,7 +67,7 @@ test "lazy plus vs greedy plus" {
6767 const allocator = std.testing.allocator;
6868
6969 // Greedy plus
70 var greedy = try Regex.compile(allocator, "a+b");
70 var greedy = try Regex.compile(allocator, std.testing.io, "a+b");
7171 defer greedy.deinit();
7272
7373 if (try greedy.find("aaab")) |match| {
@@ -80,7 +80,7 @@ test "lazy plus vs greedy plus" {
8080 }
8181
8282 // Lazy plus
83 var lazy = try Regex.compile(allocator, "a+?b");
83 var lazy = try Regex.compile(allocator, std.testing.io, "a+?b");
8484 defer lazy.deinit();
8585
8686 if (try lazy.find("aaab")) |match| {
@@ -95,7 +95,7 @@ test "lazy plus vs greedy plus" {
9595
9696test "lazy optional: a?? matches minimal (zero)" {
9797 const allocator = std.testing.allocator;
98 var regex = try Regex.compile(allocator, "a??b");
98 var regex = try Regex.compile(allocator, std.testing.io, "a??b");
9999 defer regex.deinit();
100100
101101 // Lazy optional prefers zero matches
@@ -112,7 +112,7 @@ test "lazy optional vs greedy optional" {
112112 const allocator = std.testing.allocator;
113113
114114 // Greedy optional
115 var greedy = try Regex.compile(allocator, "a?b");
115 var greedy = try Regex.compile(allocator, std.testing.io, "a?b");
116116 defer greedy.deinit();
117117
118118 if (try greedy.find("ab")) |match| {
@@ -125,7 +125,7 @@ test "lazy optional vs greedy optional" {
125125 }
126126
127127 // Lazy optional
128 var lazy = try Regex.compile(allocator, "a??b");
128 var lazy = try Regex.compile(allocator, std.testing.io, "a??b");
129129 defer lazy.deinit();
130130
131131 if (try lazy.find("ab")) |match| {
@@ -140,7 +140,7 @@ test "lazy optional vs greedy optional" {
140140
141141test "lazy repeat: a{2,4}? matches minimal" {
142142 const allocator = std.testing.allocator;
143 var regex = try Regex.compile(allocator, "a{2,4}?b");
143 var regex = try Regex.compile(allocator, std.testing.io, "a{2,4}?b");
144144 defer regex.deinit();
145145
146146 // Lazy repeat matches minimum (2 'a's)
@@ -157,7 +157,7 @@ test "lazy repeat vs greedy repeat" {
157157 const allocator = std.testing.allocator;
158158
159159 // Greedy repeat
160 var greedy = try Regex.compile(allocator, "a{2,4}b");
160 var greedy = try Regex.compile(allocator, std.testing.io, "a{2,4}b");
161161 defer greedy.deinit();
162162
163163 if (try greedy.find("aaaaab")) |match| {
@@ -170,7 +170,7 @@ test "lazy repeat vs greedy repeat" {
170170 }
171171
172172 // Lazy repeat
173 var lazy = try Regex.compile(allocator, "a{2,4}?b");
173 var lazy = try Regex.compile(allocator, std.testing.io, "a{2,4}?b");
174174 defer lazy.deinit();
175175
176176 if (try lazy.find("aaaaab")) |match| {
@@ -185,7 +185,7 @@ test "lazy repeat vs greedy repeat" {
185185
186186test "lazy quantifier in alternation" {
187187 const allocator = std.testing.allocator;
188 var regex = try Regex.compile(allocator, "a*?b|c");
188 var regex = try Regex.compile(allocator, std.testing.io, "a*?b|c");
189189 defer regex.deinit();
190190
191191 try std.testing.expect(try regex.isMatch("b"));
@@ -195,7 +195,7 @@ test "lazy quantifier in alternation" {
195195
196196test "multiple lazy quantifiers" {
197197 const allocator = std.testing.allocator;
198 var regex = try Regex.compile(allocator, "a*?b+?c");
198 var regex = try Regex.compile(allocator, std.testing.io, "a*?b+?c");
199199 defer regex.deinit();
200200
201201 if (try regex.find("aaabbbbc")) |match| {
@@ -210,7 +210,7 @@ test "multiple lazy quantifiers" {
210210
211211test "lazy quantifier with character class" {
212212 const allocator = std.testing.allocator;
213 var regex = try Regex.compile(allocator, "[a-z]+?\\d");
213 var regex = try Regex.compile(allocator, std.testing.io, "[a-z]+?\\d");
214214 defer regex.deinit();
215215
216216 if (try regex.find("abc123")) |match| {
@@ -225,7 +225,7 @@ test "lazy quantifier with character class" {
225225
226226test "lazy star with dot" {
227227 const allocator = std.testing.allocator;
228 var regex = try Regex.compile(allocator, ".*?x");
228 var regex = try Regex.compile(allocator, std.testing.io, ".*?x");
229229 defer regex.deinit();
230230
231231 if (try regex.find("abcxyz")) |match| {
@@ -240,7 +240,7 @@ test "lazy star with dot" {
240240
241241test "lazy quantifier in capture group" {
242242 const allocator = std.testing.allocator;
243 var regex = try Regex.compile(allocator, "(a+?)b");
243 var regex = try Regex.compile(allocator, std.testing.io, "(a+?)b");
244244 defer regex.deinit();
245245
246246 if (try regex.find("aaab")) |match| {
@@ -258,7 +258,7 @@ test "lazy quantifier in capture group" {
258258
259259test "lazy repeat {n,}?" {
260260 const allocator = std.testing.allocator;
261 var regex = try Regex.compile(allocator, "a{2,}?b");
261 var regex = try Regex.compile(allocator, std.testing.io, "a{2,}?b");
262262 defer regex.deinit();
263263
264264 if (try regex.find("aaaaab")) |match| {
@@ -274,7 +274,7 @@ test "lazy repeat {n,}?" {
274274test "lazy quantifier backtracking" {
275275 const allocator = std.testing.allocator;
276276 // Even though lazy, it must backtrack if necessary to match
277 var regex = try Regex.compile(allocator, "a*?aab");
277 var regex = try Regex.compile(allocator, std.testing.io, "a*?aab");
278278 defer regex.deinit();
279279
280280 if (try regex.find("aaab")) |match| {
@@ -289,7 +289,7 @@ test "lazy quantifier backtracking" {
289289
290290test "nested lazy quantifiers" {
291291 const allocator = std.testing.allocator;
292 var regex = try Regex.compile(allocator, "(a*?b+?)*?c");
292 var regex = try Regex.compile(allocator, std.testing.io, "(a*?b+?)*?c");
293293 defer regex.deinit();
294294
295295 try std.testing.expect(try regex.isMatch("c"));
@@ -299,7 +299,7 @@ test "nested lazy quantifiers" {
299299
300300test "lazy quantifier at end of pattern" {
301301 const allocator = std.testing.allocator;
302 var regex = try Regex.compile(allocator, "a+?");
302 var regex = try Regex.compile(allocator, std.testing.io, "a+?");
303303 defer regex.deinit();
304304
305305 if (try regex.find("aaa")) |match| {
@@ -318,10 +318,10 @@ test "lazy vs greedy performance comparison" {
318318 const input = "a" ** 100 ++ "b";
319319
320320 // Both should match, but with different lengths
321 var greedy = try Regex.compile(allocator, "a*b");
321 var greedy = try Regex.compile(allocator, std.testing.io, "a*b");
322322 defer greedy.deinit();
323323
324 var lazy = try Regex.compile(allocator, "a*?b");
324 var lazy = try Regex.compile(allocator, std.testing.io, "a*?b");
325325 defer lazy.deinit();
326326
327327 // Greedy matches all 100 'a's + 'b'