Expand description
§rusty_expressions – Oniguruma, remade in pure Rust
An Oniguruma-class regular-expression engine: named groups, look-around,
backreferences, subexp calls, atomic and possessive groups, absent
expressions, conditionals, callouts, per-regex encodings and pluggable
syntax dialects. No C, no FFI, no onig-sys, and it runs on
wasm32-unknown-unknown – tools/wasm-smoke executes a battery there
under Node, rather than trusting that it compiled.
no_std + alloc holds with default-features = false. The default
rusty-alloc feature installs rusty_alloc as the global allocator and
brings std with it.
It is match-equivalent to Oniguruma 6.9.10 on a harvested corpus and on
tens of thousands of differential cases run against live libonig, and
about 3x faster than libonig on search.
use rusty_expressions::{Encoding, Options, Regex, Syntax};
let re = Regex::new("ca+t", Options::NONE, Encoding::UTF8, Syntax::ONIGURUMA)?;
let m = re.search(b"one cat two")?.expect("match");
assert_eq!(m.range(), 4..7);Offsets are byte offsets into the haystack, exactly as Oniguruma’s
OnigRegion reports them.
§Known differences from libonig
tools/onig-bench --example oracle_audit runs every pattern against live
libonig across 17 encodings, 11 syntax dialects and the option matrix –
68,450 checks. Twelve differ, all one case, and it is written down here
rather than rounded off:
In the EUC encodings, on input that is not valid in that encoding,
libonig can report a match starting inside a character. Its character walk
treats AD 61 in EUC-JP as one two-byte character – .. spans it and
[a-z]+ finds nothing in it – but its literal byte-scan finds the 61
and its left_adjust_char_head accepts that offset as a character head, so
a bare a matches there. We do not reproduce that: which patterns take
that path depends on libonig’s internal optimiser, and reporting a match
that begins mid-character is the worse of the two answers. On well-formed
input the two agree everywhere.
Everything else the audit covers agrees exactly, including all 11 syntax dialects, all 17 encodings on well-formed input, and 60,000 randomised UTF-8 cases.
Modules§
- compat
compat - Optional Oniguruma-shaped C ABI (
onig_new/regex_t). - count
- Deterministic work counters for the expressions VM.
Structs§
- Callout
Ctx - Context passed to a callout.
- Capture
Tree - One node in the capture-history tree (
OnigCaptureTreeNode). - Encoding
- Built-in encodings plus a hook for user encodings (OnigEncodingType).
- Error
- Engine error. Pattern-position is set for compile failures.
- Match
Param - Limits applied during match/search. 0 on a counter means unlimited.
- Options
- Compile- and search-time option bits (Oniguruma
OnigOptionType). - RegSet
- Set of compiled regexes. All must share an encoding. FIND_LONGEST is refused.
- Regex
- Compiled regular expression.
Send + Sync. - Region
- One match: whole-match range plus numbered (and optional named) groups.
- ReqLit
- A byte sequence every match must contain, with its distance from the match start, and optionally the class run that must immediately precede it.
- Syntax
- Syntax operator/behavior bits (
OnigSyntaxType). - User
Property - User-defined Unicode property: name -> inclusive ranges.
Enums§
- Callout
Dir - Direction a contents-callout fires.
- Callout
Result - Result of a callout.
- Error
Kind - Discriminated error kind (Oniguruma codes mapped to Rust).
Constants§
- DEFAULT_
MATCH_ STACK_ LIMIT - Finite match-stack default (Oniguruma ships 0/unlimited).
- DEFAULT_
RETRY_ LIMIT_ IN_ MATCH - Oniguruma default: 10_000_000 retries in match. 0 = unlimited.
- DEFAULT_
RETRY_ LIMIT_ IN_ SEARCH - Finite search-retry default (Oniguruma ships 0/unlimited; we bound wasm/mesh).
Functions§
- builtin_
skip - A ready-made hook that always asks the engine to skip.
- describe
- Format a contents-callout body for debugging (no C callback).
- find_
all - Grep-like op: return byte ranges of matches of
patterninhay. - find_
all_ str - UTF-8 convenience for
find_all. - format_
matches - Format matches for a CLI/example surface.
- is_
match_ str - True if
patternmatches anywhere inhay. - rusty_
alloc_ enabled - Whether this build installed
rusty_allocas the global allocator. - scan
- Scan
hayfor non-overlapping matches. Empty matches advance one character. - sql_
syntax - SQL-like variable metas:
%=.*,_=.
Type Aliases§
- Callout
Fn fnpointer:Send + Sync, no capture. Closures belong in a match-time wrapper.