javelin-pattern 0.1.0

Rust bindings to Jeffrey Lim's JavelinPattern regular expression engine.
Documentation
  • Coverage
  • 100%
    42 out of 42 items documented2 out of 38 items with examples
  • Size
  • Source code size: 37.4 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 547.8 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 21s Average build duration of successful builds.
  • all releases: 20s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • 9cel/javelin-rs
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • 9cel

javelin-pattern

Rust bindings to Jeffrey Lim's JavelinPattern regular expression engine. The workspace follows the division used by rust-pcre2: javelin-pattern provides the safe API, and javelin-sys exposes the C API and builds a vendored copy of the engine.

[dependencies]
javelin-pattern = "0.1.0"
use javelin_pattern::bytes::Regex;
use std::ops::ControlFlow;

let re = Regex::new(r"(\w+)=(\d+)").unwrap();
let captures = re.captures(b"answer=42").unwrap();
assert_eq!(captures.get(1).unwrap().as_bytes(), b"answer");
assert_eq!(captures.get(2).unwrap().as_bytes(), b"42");

let mut ranges = Vec::new();
let result = re.scan(b"x=1 y=2", |matched| {
    ranges.push(matched.range());
    ControlFlow::<()>::Continue(())
});
assert_eq!(result, ControlFlow::Continue(()));
assert_eq!(ranges, [0..3, 4..7]);

The API matches byte slices and reports byte offsets. RegexBuilder configures case folding, multiline matching, UTF-8, Unicode properties, and glob syntax. UTF-8 decoding, Unicode character classes (ucp), and Unicode case folding are independent options, as in JavelinPattern. Patterns are Rust strings; use \x00 to match a NUL byte instead of putting a literal NUL in the pattern.

scan and scan_captures visit non-overlapping matches synchronously. Return ControlFlow::Break(value) to stop immediately. After an empty match, the engine tries nonempty alternatives at the same position before advancing. Capture groups are numbered; unmatched groups return None. Matches and captures borrow the input and can outlive the regex or a scan callback. Clones share the compiled pattern. Callback panics propagate after the native scan returns.

This initial wrapper covers compilation, matching, numbered captures, and callback scanning. The full native API, including bytecode compilation, remains available through javelin-sys.

Building

Rust 1.85 or newer, Clang with C++17 support, and an archiver are required. The native build defaults to clang++; the usual cc crate variables such as CXX, target-specific CXX, CXXFLAGS, and AR are supported. The engine is compiled with its optimized build settings even in Cargo's debug profile.

The build targets x86_64 and aarch64 Linux/macOS. Local validation has been performed on x86_64 Linux; Windows is not supported by this initial build script. For cross-compilation, provide a host Clang and a target Clang/toolchain using HOST_CXX and target-specific CXX settings. The assembler is built for the host.

All native sources are included in javelin-sys. Native compilation requires no system Javelin installation, Git checkout, network download, Make, Python, or bindgen. Generated C++ and compiled objects are written only under Cargo's output directory.

cargo test --workspace
cargo clippy --workspace --all-targets -- -D warnings
cargo fmt --all --check
cargo package --workspace --allow-dirty

Publish javelin-sys first, then javelin-pattern once the dependency is available on crates.io. Both manifests contain versioned dependencies and package metadata.

License

The Rust bindings are BSD-3-Clause licensed. JavelinPattern is copyright Jeffrey Lim and is distributed under its original BSD-3-Clause license in javelin-sys/upstream/LICENSE.TXT. Unicode data is covered by javelin-sys/upstream/tools/unicode/LICENSE.txt (Unicode-3.0).