#![allow(dead_code)]
mod compile;
mod matcher;
mod matching;
mod optimize;
mod parse;
mod repr;
mod state;
mod tests;
use std::iter::FromIterator;
pub fn substring(s: &str, (from, len): (usize, usize)) -> String {
String::from_iter(s.chars().skip(from).take(len))
}
pub fn render_graph(re: &str) -> String {
return format!(
"digraph st {{ {} }}",
state::dot(&compile::start_compile(parse::parse(re).as_ref().unwrap()))
);
}
fn parse(re: &str) -> Result<repr::Pattern, String> {
return parse::parse(re);
}
fn compile_and_match(re: &repr::Pattern, s: &str) -> (bool, Vec<(usize, usize)>) {
let compiled = compile::start_compile(re);
matching::do_match(&compiled, s)
}
pub fn match_re_str(re: &str, s: &str) -> Result<(bool, Vec<(usize, usize)>), String> {
return Ok(compile_and_match(&optimize::optimize(parse::parse(re)?), s));
}
pub fn compile(re: &str) -> Result<state::CompiledRE, String> {
Ok(state::CompiledRE(compile::start_compile(
&optimize::optimize(parse(re)?),
)))
}
pub fn match_re(re: &state::CompiledRE, s: &str) -> (bool, Vec<(usize, usize)>) {
matching::do_match(&re.0, s)
}