Files
@ 1e7b35645ea4
Branch filter:
Location: Regular-Expresso/src/main.rs - annotation
1e7b35645ea4
1.2 KiB
application/rls-services+xml
renamed the package to regular-expresso
f0b3b1bd87f4 1e7b35645ea4 f4558f3f9f5e f0b3b1bd87f4 a86ff65ec321 f03565ba6137 1a11f659e7b5 ac6c57072747 ac6c57072747 ac6c57072747 ac6c57072747 ac6c57072747 ac6c57072747 ac6c57072747 7e640b0cffa7 7e640b0cffa7 7e640b0cffa7 7e640b0cffa7 1a11f659e7b5 1a11f659e7b5 f4558f3f9f5e f0b3b1bd87f4 f0b3b1bd87f4 f0b3b1bd87f4 f0b3b1bd87f4 f0b3b1bd87f4 f0b3b1bd87f4 ac6c57072747 ac6c57072747 f0b3b1bd87f4 f0b3b1bd87f4 f0b3b1bd87f4 ac6c57072747 f0f9655e62ee f0f9655e62ee ac6c57072747 ac6c57072747 f0f9655e62ee f0f9655e62ee f0b3b1bd87f4 08f1519c859e f0b3b1bd87f4 f0b3b1bd87f4 f0b3b1bd87f4 | use std::env;
use regular_expresso::RegexpDFA;
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)", "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"] {
println!("# {pattern}");
match RegexpDFA::new(&pattern.to_string()) {
Ok(r) => {
for &t in tests.iter() {
println!("{t} {}", r.eval(t.to_string()));
}
println!();
},
Err(e) => {
println!("{e}");
continue;
}
}
}
}
fn main() {
let args: Vec<String> = env::args().collect();
match args[1].as_str() {
"test" => test(),
"match" => {
match RegexpDFA::new(&args[2].to_string()) {
Ok(r) => println!("{}", r.eval(args[3].to_string())),
Err(e) => {
panic!("ERROR: {e}");
}
}
},
"compare" => {
let r1 = RegexpDFA::new(&args[2].to_string()).unwrap_or_else(|e| panic!("ERROR: {e}"));
let r2 = RegexpDFA::new(&args[3].to_string()).unwrap_or_else(|e| panic!("ERROR: {e}"));
println!("{}", r1.find_distinguishing_string(&r2).unwrap_or("None".to_string()));
},
s => {
println!("An unknown command: \"{s}\". Use \"match\", \"compare\" or \"test\".")
}
}
}
|