Skip to main content

Crate rusty_expressions

Crate rusty_expressions 

Source
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-unknowntools/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§

compatcompat
Optional Oniguruma-shaped C ABI (onig_new / regex_t).
count
Deterministic work counters for the expressions VM.

Structs§

CalloutCtx
Context passed to a callout.
CaptureTree
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.
MatchParam
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).
UserProperty
User-defined Unicode property: name -> inclusive ranges.

Enums§

CalloutDir
Direction a contents-callout fires.
CalloutResult
Result of a callout.
ErrorKind
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 pattern in hay.
find_all_str
UTF-8 convenience for find_all.
format_matches
Format matches for a CLI/example surface.
is_match_str
True if pattern matches anywhere in hay.
rusty_alloc_enabled
Whether this build installed rusty_alloc as the global allocator.
scan
Scan hay for non-overlapping matches. Empty matches advance one character.
sql_syntax
SQL-like variable metas: % = .*, _ = .

Type Aliases§

CalloutFn
fn pointer: Send + Sync, no capture. Closures belong in a match-time wrapper.