Files
@ f0b3b1bd87f4
Branch filter:
Location: Regular-Expresso/src/main.rs - annotation
f0b3b1bd87f4
993 B
application/rls-services+xml
a basic command line interface
f0b3b1bd87f4 e93b264ec5cc f4558f3f9f5e f0b3b1bd87f4 a86ff65ec321 61a2b8f09823 1a11f659e7b5 7e640b0cffa7 4f7b6352013d 7e640b0cffa7 7e640b0cffa7 7e640b0cffa7 7e640b0cffa7 7e640b0cffa7 1a11f659e7b5 1a11f659e7b5 1a11f659e7b5 1a11f659e7b5 1a11f659e7b5 f4558f3f9f5e f0b3b1bd87f4 f0b3b1bd87f4 f0b3b1bd87f4 f0b3b1bd87f4 f0b3b1bd87f4 f0b3b1bd87f4 f0b3b1bd87f4 f0b3b1bd87f4 f0b3b1bd87f4 f0b3b1bd87f4 f0b3b1bd87f4 f0b3b1bd87f4 f0b3b1bd87f4 f0b3b1bd87f4 f0b3b1bd87f4 f0b3b1bd87f4 f0b3b1bd87f4 f0b3b1bd87f4 f0b3b1bd87f4 | use std::env;
use regexp::Regexp;
fn test() {
let tests = ["", "a", "ab", "aabb", "abab", "abcd", "abcbcdbcd"];
for pattern in ["a(b|c)", "a*b*", "(ab)*", "a((bc)*d)*", "(a|b)*a(a|b)(a|b)(a|b)", "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"] {
println!("# {pattern}");
let r = match Regexp::new(&pattern.to_string()) {
Ok(r1) => r1.determinize().reduce().normalize(),
Err(e) => {
println!("{e}");
continue;
}
};
for &t in tests.iter() {
println!("{t} {}", r.eval(t.to_string()));
}
println!();
}
}
fn main() {
let args: Vec<String> = env::args().collect();
match args[1].as_str() {
"test" => test(),
"match" => {
let r = match Regexp::new(&args[2].to_string()) {
Ok(r1) => r1.determinize().reduce().normalize(),
Err(e) => {
panic!("ERROR: {e}");
}
};
println!("{}", r.eval(args[3].to_string()));
}
s => {
println!("An unknown command: \"{s}\". Use \"match\" or \"test\".")
}
}
}
|