also looking at this
Port to latest zig-master
#2
53 files
+1149
-1017
| @@ -386,35 +386,31 @@ zig build wasm | ||
| 386 | 386 | ```javascript |
| 387 | 387 | // Load WASM module |
| 388 | 388 | const wasmModule = await WebAssembly.instantiateStreaming( |
| 389 | fetch('zig-regex.wasm') | |
| 389 | fetch("zig-regex.wasm"), | |
| 390 | 390 | ); |
| 391 | 391 | |
| 392 | const { | |
| 393 | zig_regex_compile, | |
| 394 | zig_regex_is_match, | |
| 395 | zig_regex_free, | |
| 396 | memory | |
| 397 | } = wasmModule.instance.exports; | |
| 392 | const { zig_regex_compile, zig_regex_is_match, zig_regex_free, memory } = | |
| 393 | wasmModule.instance.exports; | |
| 398 | 394 | |
| 399 | 395 | // Helper to convert JS string to WASM memory |
| 400 | 396 | function 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; | |
| 405 | 401 | } |
| 406 | 402 | |
| 407 | 403 | // Compile regex |
| 408 | const pattern = stringToWasm('\\d+'); | |
| 404 | const pattern = stringToWasm("\\d+"); | |
| 409 | 405 | const flags = 0; // No flags |
| 410 | 406 | const errorPtr = allocate(4); |
| 411 | 407 | const regex = zig_regex_compile(pattern, flags, errorPtr); |
| 412 | 408 | |
| 413 | 409 | // Test match |
| 414 | const input = stringToWasm('hello123'); | |
| 410 | const input = stringToWasm("hello123"); | |
| 415 | 411 | const isMatch = zig_regex_is_match(regex, input, errorPtr); |
| 416 | 412 | |
| 417 | console.log('Match:', isMatch); | |
| 413 | console.log("Match:", isMatch); | |
| 418 | 414 | |
| 419 | 415 | // Clean up |
| 420 | 416 | zig_regex_free(regex); |
| @@ -476,7 +472,7 @@ Warnings (2): | ||
| 476 | 472 | |
| 477 | 473 | The library automatically chooses between two engines: |
| 478 | 474 | |
| 479 | - **Thompson NFA**: O(n*m) performance for basic patterns | |
| 475 | - **Thompson NFA**: O(n\*m) performance for basic patterns | |
| 480 | 476 | - **Backtracking Engine**: Supports advanced features (lazy quantifiers, lookahead, lookbehind, backreferences) |
| 481 | 477 | |
| 482 | 478 | ```zig |