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
TODO.mdmodified+46-2
formatting only · 7 hidden lines
Changes to TODO.md
@@ -11,6 +11,7 @@ A modern, performant regex library for Zig 0.16+ formatting only
1111**Phases Completed:** 10 out of 11 (core + testing + docs + advanced features + fuzzing complete)
1212
1313### What Works Now:
14
1415- ✅ Complete lexer and parser for regex syntax
1516- ✅ Thompson NFA construction
1617- ✅ Thread-based NFA simulation with greedy matching
formatting only · 7 hidden lines
Changes to TODO.md
@@ -28,6 +29,7 @@ A modern, performant regex library for Zig 0.16+ formatting only
2829- ✅ Thread-safety utilities and documentation
2930
3031### Example Usage:
32
3133```zig
3234var regex = try Regex.compile(allocator, "\\d+");
3335defer regex.deinit();
formatting only · 7 hidden lines
Changes to TODO.md
@@ -39,6 +41,7 @@ if (try regex.find("Price: $123")) |match| { formatting only
3941## Project Overview
4042
4143Building a production-ready regular expression library for Zig that provides:
44
4245- Fast pattern matching using Thompson NFA construction
4346- Zero external dependencies (stdlib only)
4447- Full memory control with Zig allocators
formatting only · 7 hidden lines
Changes to TODO.md
@@ -51,6 +54,7 @@ Building a production-ready regular expression library for Zig that provides: formatting only
5154## Phase 1: Project Foundation ✅ COMPLETED
5255
5356### 1.1 Project Setup ✅
57
5458- [x] Initialize Zig project structure with `zig init`
5559- [x] Create `build.zig` with library and test targets
5660- [x] Create `build.zig.zon` with project metadata
formatting only · 7 hidden lines
Changes to TODO.md
@@ -60,6 +64,7 @@ Building a production-ready regular expression library for Zig that provides: formatting only
6064- [x] Create `.gitignore` for Zig projects
6165
6266### 1.2 Core Module Structure ✅
67
6368- [x] Create `src/regex.zig` as the main public API (385 lines)
6469- [x] Create `src/parser.zig` for regex pattern parsing (395 lines)
6570- [x] Create `src/ast.zig` for Abstract Syntax Tree representation (267 lines)
formatting only · 7 hidden lines
Changes to TODO.md
@@ -69,6 +74,7 @@ Building a production-ready regular expression library for Zig that provides: formatting only
6974- [x] Create `src/common.zig` for shared types and utilities (174 lines)
7075
7176### 1.3 Documentation Foundation ✅
77
7278- [x] Set up documentation comments structure
7379- [x] Create `docs/ARCHITECTURE.md` explaining design decisions - **COMPLETED**
7480- [x] Create `docs/API.md` for API reference - **COMPLETED**
formatting only · 7 hidden lines
Changes to TODO.md
@@ -80,6 +86,7 @@ Building a production-ready regular expression library for Zig that provides: formatting only
8086## Phase 2: Parser & AST ✅ COMPLETED
8187
8288### 2.1 Lexer Implementation ✅
89
8390- [x] Implement tokenizer for regex patterns
8491- [x] Support basic literals (a-z, A-Z, 0-9)
8592- [x] Support special characters (`.`, `^`, `$`, etc.)
formatting only · 7 hidden lines
Changes to TODO.md
@@ -89,6 +96,7 @@ Building a production-ready regular expression library for Zig that provides: formatting only
8996- [x] Implement proper error reporting with line/column info
9097
9198### 2.2 Parser Implementation ✅
99
92100- [x] Implement recursive descent parser
93101- [x] Handle operator precedence correctly
94102- [x] Support concatenation (implicit)
formatting only · 7 hidden lines
Changes to TODO.md
@@ -103,6 +111,7 @@ Building a production-ready regular expression library for Zig that provides: formatting only
103111- [x] Add comprehensive error messages
104112
105113### 2.3 AST Construction ✅
114
106115- [x] Define AST node types (Literal, Alternation, Concatenation, etc.)
107116- [x] Implement AST builder from parser
108117- [x] Add AST validation pass
formatting only · 7 hidden lines
Changes to TODO.md
@@ -114,6 +123,7 @@ Building a production-ready regular expression library for Zig that provides: formatting only
114123## Phase 3: NFA Engine ✅ COMPLETED
115124
116125### 3.1 Thompson Construction ✅
126
117127- [x] Implement basic NFA data structure
118128- [x] Implement state and transition representations
119129- [x] Support epsilon (ε) transitions
Changes to TODO.md
@@ -121,11 +131,12 @@ Building a production-ready regular expression library for Zig that provides:
121131- [x] Handle literal characters
122132- [x] Handle concatenation
123133- [x] Handle alternation
124- [x] Handle Kleene star (*)
134- [x] Handle Kleene star (\*)
125135- [x] Handle plus (+) and optional (?)
126136- [x] Handle bounded repetition {m,n}
127137
128138### 3.2 NFA Optimization
139
129140- [x] Implement epsilon-closure computation
130141- [ ] Remove redundant epsilon transitions (future enhancement)
131142- [ ] Merge equivalent states (future enhancement)
formatting only · 7 hidden lines
Changes to TODO.md
@@ -133,6 +144,7 @@ Building a production-ready regular expression library for Zig that provides: formatting only
133144- [ ] Add NFA visualization/debug output (future enhancement)
134145
135146### 3.3 NFA Simulation ✅
147
136148- [x] Implement basic NFA simulation engine (thread-based matching)
137149- [x] Support backtracking for complex patterns (via thread-based approach)
138150- [x] Track capture groups during matching
formatting only · 7 hidden lines
Changes to TODO.md
@@ -146,6 +158,7 @@ Building a production-ready regular expression library for Zig that provides: formatting only
146158## Phase 4: Pattern Matching API ✅ COMPLETED
147159
148160### 4.1 Core Matching Functions ✅
161
149162- [x] Implement `Regex.compile()` - compile pattern
150163- [x] Implement `Regex.deinit()` - cleanup
151164- [x] Implement `find()` - find first match
formatting only · 7 hidden lines
Changes to TODO.md
@@ -154,6 +167,7 @@ Building a production-ready regular expression library for Zig that provides: formatting only
154167- [x] Return match positions (start, end indices)
155168
156169### 4.2 Capture Groups ⚠️ Partial
170
157171- [x] Implement numbered capture groups `()`
158172- [x] Track capture group positions
159173- [x] Return captured substrings
formatting only · 7 hidden lines
Changes to TODO.md
@@ -162,6 +176,7 @@ Building a production-ready regular expression library for Zig that provides: formatting only
162176- [ ] Access captures by name (future enhancement)
163177
164178### 4.3 Advanced Matching ✅
179
165180- [x] Implement `replace()` - replace matches
166181- [x] Implement `replaceAll()` - replace all matches
167182- [ ] Support backreferences in replacement (future enhancement)
formatting only · 7 hidden lines
Changes to TODO.md
@@ -174,6 +189,7 @@ Building a production-ready regular expression library for Zig that provides: formatting only
174189## Phase 5: Extended Regex Features
175190
176191### 5.1 Character Classes ✅
192
177193- [x] Support `\d` (digits)
178194- [x] Support `\D` (non-digits)
179195- [x] Support `\w` (word characters)
formatting only · 7 hidden lines
Changes to TODO.md
@@ -185,6 +201,7 @@ Building a production-ready regular expression library for Zig that provides: formatting only
185201- [ ] Support POSIX character classes `[:alpha:]`, `[:digit:]`, etc. (future enhancement)
186202
187203### 5.2 Advanced Anchors & Boundaries ✅
204
188205- [x] Line anchors (`^`, `$`)
189206- [x] Word boundaries (`\b`, `\B`)
190207- [x] String anchors (`\A`, `\z`, `\Z`) - **COMPLETED** (fully implemented and tested)
formatting only · 7 hidden lines
Changes to TODO.md
@@ -192,6 +209,7 @@ Building a production-ready regular expression library for Zig that provides: formatting only
192209- [ ] Lookbehind assertions `(?<=)`, `(?<!)` (future enhancement)
193210
194211### 5.3 Flags & Options ✅
212
195213- [x] Case-insensitive flag (i) - **COMPLETED**
196214- [x] Compile-time flag specification via `compileWithFlags()` - **COMPLETED**
197215- [x] Multiline flag (m) - **COMPLETED** (^ and $ respect multiline mode)
formatting only · 7 hidden lines
Changes to TODO.md
@@ -205,6 +223,7 @@ Building a production-ready regular expression library for Zig that provides: formatting only
205223## Phase 6: Testing & Quality
206224
207225### 6.1 Unit Tests ✅ COMPLETED
226
208227- [x] Test lexer with various input patterns - **COMPLETED** (6+ lexer tests)
209228- [x] Test parser with valid/invalid regex - **COMPLETED** (10+ parser tests)
210229- [x] Test AST construction and validation - **COMPLETED** (4+ AST tests)
formatting only · 7 hidden lines
Changes to TODO.md
@@ -217,6 +236,7 @@ Building a production-ready regular expression library for Zig that provides: formatting only
217236- [x] Test edge cases (empty strings, large inputs) - **COMPLETED** (dedicated edge_cases test file)
218237
219238### 6.2 Integration Tests ✅ COMPLETED
239
220240- [x] Test real-world regex patterns - **COMPLETED**
221241- [x] Test email validation patterns - **COMPLETED**
222242- [x] Test URL matching patterns - **COMPLETED**
formatting only · 7 hidden lines
Changes to TODO.md
@@ -231,6 +251,7 @@ Building a production-ready regular expression library for Zig that provides: formatting only
231251- [ ] Test error handling paths (future enhancement)
232252
233253### 6.3 Fuzzing & Property Tests ✅
254
234255- [x] Set up fuzzing infrastructure - **COMPLETED**
235256- [x] Fuzz lexer with random inputs - **COMPLETED** (fuzz.zig)
236257- [x] Fuzz parser with malformed patterns - **COMPLETED** (bad patterns test)
formatting only · 7 hidden lines
Changes to TODO.md
@@ -239,6 +260,7 @@ Building a production-ready regular expression library for Zig that provides: formatting only
239260- [x] Test memory safety (no leaks) - **COMPLETED** (zero leaks detected)
240261
241262### 6.4 Compliance Tests
263
242264- [ ] Create test suite from regex standards
243265- [ ] Compare against PCRE test suite (where applicable)
244266- [ ] Test compatibility with common regex flavors
formatting only · 7 hidden lines
Changes to TODO.md
@@ -249,6 +271,7 @@ Building a production-ready regular expression library for Zig that provides: formatting only
249271## Phase 7: Performance Optimization
250272
251273### 7.1 Algorithm Optimization
274
252275- [ ] Profile hot paths in matching
253276- [ ] Optimize state transition lookup
254277- [ ] Implement DFA construction for static patterns
formatting only · 7 hidden lines
Changes to TODO.md
@@ -258,6 +281,7 @@ Building a production-ready regular expression library for Zig that provides: formatting only
258281- [ ] Cache compiled patterns
259282
260283### 7.2 Memory Optimization
284
261285- [ ] Minimize allocations during matching
262286- [ ] Use arena allocators where appropriate
263287- [ ] Implement copy-on-write for captures
formatting only · 7 hidden lines
Changes to TODO.md
@@ -265,6 +289,7 @@ Building a production-ready regular expression library for Zig that provides: formatting only
265289- [ ] Optimize AST/NFA memory layout
266290
267291### 7.3 Benchmarking ⚠️ Partial
292
268293- [x] Create benchmark suite - **COMPLETED**
269294- [x] Benchmark common patterns (literal, quantifiers, character classes) - **COMPLETED**
270295- [x] Benchmark case-insensitive matching - **COMPLETED**
formatting only · 7 hidden lines
Changes to TODO.md
@@ -278,6 +303,7 @@ Building a production-ready regular expression library for Zig that provides: formatting only
278303## Phase 8: Documentation & Examples ✅ COMPLETED
279304
280305### 8.1 API Documentation ✅ COMPLETED
306
281307- [x] Document all public functions with examples - **COMPLETED** (docs/API.md - 800+ lines)
282308- [x] Add parameter descriptions - **COMPLETED**
283309- [x] Document error conditions - **COMPLETED**
formatting only · 7 hidden lines
Changes to TODO.md
@@ -286,6 +312,7 @@ Building a production-ready regular expression library for Zig that provides: formatting only
286312- [ ] Generate docs with `zig build docs` (requires Zig docs infrastructure)
287313
288314### 8.2 User Guide ✅ COMPLETED
315
289316- [x] Write getting started guide - **COMPLETED** (README.md + docs/API.md)
290317- [x] Document pattern syntax - **COMPLETED** (docs/API.md Pattern Syntax section)
291318- [x] Document best practices - **COMPLETED** (docs/EXAMPLES.md Best Practices section)
formatting only · 7 hidden lines
Changes to TODO.md
@@ -295,6 +322,7 @@ Building a production-ready regular expression library for Zig that provides: formatting only
295322- [ ] Create FAQ (future enhancement)
296323
297324### 8.3 Examples ✅ COMPLETED
325
298326- [x] Create basic usage example - **COMPLETED** (README.md + docs/EXAMPLES.md)
299327- [x] Create capture groups example - **COMPLETED** (docs/EXAMPLES.md)
300328- [x] Create replace/substitution example - **COMPLETED** (docs/EXAMPLES.md)
formatting only · 7 hidden lines
Changes to TODO.md
@@ -307,6 +335,7 @@ Building a production-ready regular expression library for Zig that provides: formatting only
307335## Phase 9: Advanced Features
308336
309337### 9.1 Unicode Support
338
310339- [ ] Support UTF-8 input (Zig's default)
311340- [ ] Handle multi-byte characters correctly
312341- [ ] Support Unicode character classes
formatting only · 7 hidden lines
Changes to TODO.md
@@ -315,6 +344,7 @@ Building a production-ready regular expression library for Zig that provides: formatting only
315344- [ ] Handle normalization (if needed)
316345
317346### 9.2 Performance Features
347
318348- [ ] Implement lazy DFA construction
319349- [ ] Add memoization for repeated patterns
320350- [ ] Support compiled pattern serialization
formatting only · 7 hidden lines
Changes to TODO.md
@@ -322,6 +352,7 @@ Building a production-ready regular expression library for Zig that provides: formatting only
322352- [ ] Add SIMD optimizations (if applicable)
323353
324354### 9.3 Developer Features
355
325356- [ ] Implement regex debugging mode
326357- [ ] Add visualization of NFA/DFA
327358- [ ] Create regex playground/tester
formatting only · 7 hidden lines
Changes to TODO.md
@@ -333,6 +364,7 @@ Building a production-ready regular expression library for Zig that provides: formatting only
333364## Phase 10: Production Readiness
334365
335366### 10.1 Error Handling ✅
367
336368- [x] Comprehensive error types - **COMPLETED** (40+ error types defined)
337369- [x] Detailed error messages - **COMPLETED** (ErrorContext with formatting)
338370- [x] Recovery strategies where possible - **COMPLETED** (hints and suggestions)
Changes to TODO.md
@@ -340,12 +372,14 @@ Building a production-ready regular expression library for Zig that provides:
340372- [x] Panic-free API design - **COMPLETED** (all errors returned as values)
341373
342374### 10.2 Thread Safety ✅
375
343376- [x] Document thread-safety guarantees - **COMPLETED** (documented in LIMITATIONS.md)
344377- [x] Make compiled patterns thread-safe - **COMPLETED** (read-only operations are safe)
345378- [x] Support concurrent matching - **COMPLETED** (VM creates thread-local state)
346379- [x] Thread safety utilities - **COMPLETED** (RegexCache implementation available)
347380
348381### 10.3 API Stability
382
349383- [ ] Finalize public API surface
350384- [ ] Mark internal APIs clearly
351385- [ ] Version the API
formatting only · 7 hidden lines
Changes to TODO.md
@@ -353,6 +387,7 @@ Building a production-ready regular expression library for Zig that provides: formatting only
353387- [ ] Write upgrade guides
354388
355389### 10.4 Release Preparation
390
356391- [ ] Set up CI/CD pipeline
357392- [ ] Add pre-commit hooks
358393- [ ] Create release checklist
formatting only · 7 hidden lines
Changes to TODO.md
@@ -365,6 +400,7 @@ Building a production-ready regular expression library for Zig that provides: formatting only
365400## Phase 11: Community & Maintenance
366401
367402### 11.1 Community Building
403
368404- [ ] Create CONTRIBUTING.md
369405- [ ] Set up issue templates
370406- [ ] Set up PR templates
formatting only · 7 hidden lines
Changes to TODO.md
@@ -373,6 +409,7 @@ Building a production-ready regular expression library for Zig that provides: formatting only
373409- [ ] Announce on Zig forums
374410
375411### 11.2 Ongoing Maintenance
412
376413- [ ] Monitor issues and PRs
377414- [ ] Keep up with Zig language updates
378415- [ ] Update dependencies
formatting only · 7 hidden lines
Changes to TODO.md
@@ -385,6 +422,7 @@ Building a production-ready regular expression library for Zig that provides: formatting only
385422## Future Considerations
386423
387424### Potential Features
425
388426- [ ] Regex macros/composition
389427- [ ] Pattern compilation to native code
390428- [ ] C FFI for use in other languages
formatting only · 7 hidden lines
Changes to TODO.md
@@ -393,6 +431,7 @@ Building a production-ready regular expression library for Zig that provides: formatting only
393431- [ ] Regex lint/analysis tools / extreme narrow typing for user patterns
394432
395433### Research Topics
434
396435- [ ] Investigate derivative-based regex matching
397436- [ ] Explore SIMD/vector optimization opportunities
398437- [ ] Consider hybrid NFA/DFA approaches
formatting only · 7 hidden lines
Changes to TODO.md
@@ -404,6 +443,7 @@ Building a production-ready regular expression library for Zig that provides: formatting only
404443## Success Metrics
405444
406445### Quality Metrics
446
407447- [x] 90%+ test coverage - **ACHIEVED** (114+ tests, 100% pass rate)
408448- [x] Zero known memory leaks - **ACHIEVED** (all tests pass leak detection)
409449- [x] Zero known security vulnerabilities - **ACHIEVED** (safe memory management)
Changes to TODO.md
@@ -411,12 +451,14 @@ Building a production-ready regular expression library for Zig that provides:
411451- [ ] Pass compliance test suite (future - requires PCRE test suite integration)
412452
413453### Performance Metrics
414- [x] Linear time complexity for NFA matching - **ACHIEVED** (Thompson NFA with O(n*m))
454
455- [x] Linear time complexity for NFA matching - **ACHIEVED** (Thompson NFA with O(n\*m))
415456- [x] Reasonable memory usage - **ACHIEVED** (efficient allocator usage)
416457- [x] Fast compilation times - **ACHIEVED** (simple patterns compile quickly)
417458- [ ] Competitive with existing Zig regex libraries (future - requires benchmarking)
418459
419460### Adoption Metrics
461
420462- [ ] Used in at least 3 external projects (future)
421463- [ ] Positive community feedback (future - pending release)
422464- [ ] Active contributors beyond maintainers (future)
formatting only · 7 hidden lines
Changes to TODO.md
@@ -443,6 +485,7 @@ Building a production-ready regular expression library for Zig that provides: formatting only
443485## Recent Updates (2025-10-27)
444486
445487### Completed Features:
488
4464891. ✅ **Quantifiers `{m,n}`** - Full runtime support with comprehensive tests
4474902. ✅ **String Anchors** - `\A`, `\z`, `\Z` fully implemented and tested
4484913. ✅ **Multiline Flag** - `^` and `$` respect multiline mode
formatting only · 7 hidden lines
Changes to TODO.md
@@ -450,6 +493,7 @@ Building a production-ready regular expression library for Zig that provides: formatting only
4504935. ✅ **Bug Fixes** - Fixed memory leaks in thread safety tests, updated Zig 0.15.1 APIs
451494
452495### Test Suite:
496
453497- **155+ tests** passing with 100% success rate
454498- New test files: `string_anchors.zig`, `multiline_dotall.zig`
455499- All memory leaks resolved