pub trait Builder {
    type Err;

    fn for_platform(
        &self,
        mode: Mode,
        match_limit: Option<MatchLimit>,
        platform: Option<&PlatformRef>
    ) -> Result<Database, Self::Err>; fn build(&self) -> Result<Database, Self::Err> { ... } fn with_groups(&self) -> Result<Database, Self::Err> { ... } }
Expand description

The regular expression pattern database builder.

Required Associated Types

The associated error which can be returned from compiling.

Required Methods

Build an expression is compiled into a Chimera database for a target platform.

Provided Methods

Build an expression is compiled into a Chimera database which can be passed to the runtime functions.

Examples
let pattern: Pattern = "/test/i".parse().unwrap();
let db = pattern.build().unwrap();
let scratch = db.alloc_scratch().unwrap();
let mut matches = vec![];
let mut errors = vec![];

db.scan("some test data", &scratch, |id, from, to, _flags, captured| {
    println!("found pattern {} : {} @ [{}, {})", id, pattern.expression, from, to);

    matches.push((from, to));

    Matching::Continue
}, |error_type, id| {
    errors.push((error_type, id));

    Matching::Skip
}).unwrap();

assert_eq!(matches, vec![(5, 9)]);
assert_eq!(errors, vec![]);

Build an expression is compiled into a Chimera database that the database as a whole for capturing groups.

Examples
let pattern: Pattern = r"/(?<word>\w+)/i".parse().unwrap();
let db = pattern.with_groups().unwrap();
let scratch = db.alloc_scratch().unwrap();
let mut matches = vec![];
let mut captures = vec![];
let mut errors = vec![];

db.scan("some test data", &scratch, |id, from, to, _flags, captured: Option<&[Capture]>| {
    println!("found pattern {} : {} @ [{}, {}), captured {:?}", id, pattern.expression, from, to, captured);

    matches.push((from, to));

    if let Some(captured) = captured {
        captures.push(captured.first().expect("captured").range());
    }

    Matching::Continue
}, |error_type, id| {
    errors.push((error_type, id));

    Matching::Skip
}).unwrap();

assert_eq!(matches, vec![(0, 4), (5, 9), (10, 14)]);
assert_eq!(captures, vec![0..4, 5..9, 10..14]);
assert_eq!(errors, vec![]);

Implementors