Crate gregex

source ·
Expand description

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:

Modules§

  • Has the implementation of a non-deterministic finite automaton (NFA).
  • Contains the translation submodules necessary to translate the raw regex to a NFA.

Macros§

  • Represents the concatenation action in regex. Can concatenate multiple nodes.
  • Represents the `or`` action in regex. Can ‘or’ multiple nodes.
  • Represents the production action in regex. This is a single node.

Functions§

  • Translates a regular expression tree to a NFA. This NFA can then be called to simulate inputs.
  • Represents a terminal in regex. This is a single character.