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
docs/ADVANCED_FEATURES.mdmodified+11-15
Changes to docs/ADVANCED_FEATURES.md
@@ -386,35 +386,31 @@ zig build wasm
386386```javascript
387387// Load WASM module
388388const wasmModule = await WebAssembly.instantiateStreaming(
389 fetch('zig-regex.wasm')
389 fetch("zig-regex.wasm"),
390390);
391391
392const {
393 zig_regex_compile,
394 zig_regex_is_match,
395 zig_regex_free,
396 memory
397} = wasmModule.instance.exports;
392const { zig_regex_compile, zig_regex_is_match, zig_regex_free, memory } =
393 wasmModule.instance.exports;
398394
399395// Helper to convert JS string to WASM memory
400396function stringToWasm(str) {
401 const bytes = new TextEncoder().encode(str + '\0');
402 const ptr = allocate(bytes.length);
403 new Uint8Array(memory.buffer, ptr, bytes.length).set(bytes);
404 return ptr;
397 const bytes = new TextEncoder().encode(str + "\0");
398 const ptr = allocate(bytes.length);
399 new Uint8Array(memory.buffer, ptr, bytes.length).set(bytes);
400 return ptr;
405401}
406402
407403// Compile regex
408const pattern = stringToWasm('\\d+');
404const pattern = stringToWasm("\\d+");
409405const flags = 0; // No flags
410406const errorPtr = allocate(4);
411407const regex = zig_regex_compile(pattern, flags, errorPtr);
412408
413409// Test match
414const input = stringToWasm('hello123');
410const input = stringToWasm("hello123");
415411const isMatch = zig_regex_is_match(regex, input, errorPtr);
416412
417console.log('Match:', isMatch);
413console.log("Match:", isMatch);
418414
419415// Clean up
420416zig_regex_free(regex);
@@ -476,7 +472,7 @@ Warnings (2):
476472
477473The library automatically chooses between two engines:
478474
479- **Thompson NFA**: O(n*m) performance for basic patterns
475- **Thompson NFA**: O(n\*m) performance for basic patterns
480476- **Backtracking Engine**: Supports advanced features (lazy quantifiers, lookahead, lookbehind, backreferences)
481477
482478```zig