5 releases

0.5.3 Apr 7, 2024
0.5.2 Apr 7, 2024
0.4.3 Feb 16, 2024

#530 in Text processing

Download history 159/week @ 2024-02-12 45/week @ 2024-02-19 24/week @ 2024-02-26 8/week @ 2024-03-11 122/week @ 2024-04-01 149/week @ 2024-04-08

271 downloads per month

MIT license

82KB
666 lines

Gregex crates.io Build Passing

Gregex is a regular expression solver which utilizes Non-deterministic Finite Automata (NFA) to simulate the input strings.

Usage

extern crate gregex;
use gregex::*;
fn main() {
    let tree = concatenate!(production!(terminal('a')), terminal('b'), terminal('c'));
    let regex = regex(&tree);
    assert!(regex.simulate("abc"));
    assert!(!regex.simulate("a"));
    assert!(regex.simulate("aaabc"));
}

Theory

The project uses Glushkov's construction algorithm for creating the NFA.

The pipeline can be summarised as below


lib.rs:

This crate provides a regular expression engine that uses a Nondeterministic finite automaton to simulate the regular expression. Here is a short example on how to use this crate

extern crate gregex;
use gregex::*;

fn main() {
    let tree = concatenate!(production!(terminal('a')), terminal('b'), terminal('c'));
    let regex = regex(&tree);
    assert!(regex.simulate("abc"));
    assert!(!regex.simulate("a"));
    assert!(regex.simulate("aaabc"));
}

The regex function uses the regular expression string to create a NFA that can be used to simulate the regular expression. The program uses the Glushkov's construction algorithm to create its NFA. The NFA is then later simulated to check if the input string matches the regular expression.

A brief overview of the pipeline: [

No runtime deps