A proposed WebAssembly System Interface API.
wasi-pattern-match
is currently in Phase 1.
TODO before entering Phase 2.
- Introduction
- Goals
- Non-goals
- API walk-through
- Detailed design discussion
- Considered alternatives
- Stakeholder Interest & Feedback
- References & acknowledgements
wasi-pattern-match
is a WASI API for scanning data and finding out matches with high performance and low latency.
- Support PCRE syntax (or subset)
- API: iterate over matches, find the first match, check existence
- Improve upon current WebAssembly performance
- Not all of the PCRE APIs are supported, e.g.: string replacement
Initial draft. APIs are subject to change.
This example creates a scanner with a given pattern, then uses the scanner to scan a block of data to get the number of email addresses.
Scanner scanner = create_scanner(["email pattern"]);
Scan result = scan_block(scanner, buffer);
println!("Number of email addresses in the block: {}", all_matches(result).len());
close_scanner(scanner)
This example creates a scanner with given patterns, then uses the scanner to scan a stream to detect dangerous traffic.
Scanner scanner = create_scanner(["dangerous url", "credit card", "phone number"]);
Stream stream = create_stream(scanner);
while (!eos) {
// Keep reading chunks from a network level stream, or an application level stream.
Scan result = scan_stream(stream, chunk);
if (has_match(result)) {
// Detected dangerous traffic, drop the connection or return an error code.
} else {
// Continue.
}
}
close_stream(stream)
close_scanner(scanner)
[This section should mostly refer to the .wit.md file that specifies the API. This section is for any discussion of the choices made in the API which don't make sense to document in the spec file itself.]
[Talk through the tradeoffs in coming to the specific design point you want to make.]
// Illustrated with example code.
[This may be an open question, in which case you should link to any active discussion threads.]
[etc.]
If a WASM runtime does not support this API, please consider to compile a regex framework to WebAssembly.
TODO before entering Phase 3.
[This should include a list of implementers who have expressed interest in implementing the proposal]
Many thanks for valuable feedback and advice from:
- [Person 1]
- [Person 2]
- [etc.]