rexen

Compile and evaluate regular expressions using Non-deterministic Finite Automata (NFAs).

Functions

pub fn compute(engine: NFA, input: String) -> Bool

Evaluates whether a given input String is matched by the provided Non-deterministic Finite Automaton (NFA).

Takes an NFA and an input string, returning True if the input is accepted by the NFA, and False otherwise.

Examples

import rexen

let assert Ok(nfa) = rexen.new("(a?b)*")
rexen.compute(nfa, "ab") // -> True
rexen.compute(nfa, "ababab") // -> True
rexen.compute(nfa, "ababa") // -> False
rexen.compute(nfa, "a") // -> False
pub fn new(expression: String) -> Result(NFA, String)

Compiles a regular expression string into a Non-deterministic Finite Automaton (NFA).

Takes a regular expression String and returns Ok(NFA) on success, or Error(String) on failure. Uses a shunting-yard algorithm to convert from infix to postfix notation Uses Thompson’s construction to construct the nfa

Examples

import rexen

case rexen.new("a?b") {
  Ok(_) -> io.println("All good")
  Error(err) -> io.println(err)
}
Search Document