pub enum Regex<T> {
Null,
Empty,
Except(Vec<T>),
Alt(Vec<T>, Vec<Regex<T>>),
And(Vec<Regex<T>>),
Not(Box<Regex<T>>),
Cat(Vec<Regex<T>>),
Kleene(Box<Regex<T>>),
}
Expand description
A regular expression over the alphabet T
.
Variants§
Null
The null set. This never matches anything.
Empty
The empty string (matches exactly “”).
Except(Vec<T>)
Matches any single character except the listed ones.
Alt(Vec<T>, Vec<Regex<T>>)
Alternation (also known as disjunction). Matches any of the contained characters, as well as any string matched by a contained regex.
And(Vec<Regex<T>>)
Conjunction. Matches iff all contained regexes match.
Not(Box<Regex<T>>)
Negation. Matches iff the contained regex does not match.
Cat(Vec<Regex<T>>)
Concatenation. Matches iff the contained regexes match in sequence.
Kleene(Box<Regex<T>>)
Kleene closure. Matches zero or more repetitions of the contained regex.
Implementations§
source§impl<T> Regex<T>
impl<T> Regex<T>
sourcepub fn nullable(&self) -> bool
pub fn nullable(&self) -> bool
Tests whether a regular expression is nullable, i.e. whether it matches the empty string.
Examples found in repository?
examples/test.rs (line 17)
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
fn main() {
let stdin = std::io::stdin();
for line in stdin.lock().lines() {
let line = line.unwrap();
match line.trim().parse::<Regex<char>>() {
Err(e) => println!("error: {}", e),
Ok(x) => {
println!("ok: {:?}", x);
let x = x.normalize();
println!("{:?}", x);
println!("{:?}", x.derivative().map(Normalize::normalize));
let (dfa, _mapping) = Dfa::from_derivatives(vec![x, Regex::Null]);
let dfa = dfa.map(|reg| reg.nullable());
println!("DFA: {:?}\n", dfa);
let mdfa = dfa.minimize().map(|x| *x);
println!("Minimized DFA: {:?}\n", mdfa);
println!("dfa == mdfa: {:?}\n", dfa == mdfa);
}
}
}
}
Trait Implementations§
source§impl<T: Ord + Clone> Differentiable<T> for Regex<T>
impl<T: Ord + Clone> Differentiable<T> for Regex<T>
fn derivative(&self) -> Derivatives<T, Regex<T>>
source§impl<T: Ord> Ord for Regex<T>
impl<T: Ord> Ord for Regex<T>
source§impl<T: PartialEq> PartialEq for Regex<T>
impl<T: PartialEq> PartialEq for Regex<T>
source§impl<T: PartialOrd> PartialOrd for Regex<T>
impl<T: PartialOrd> PartialOrd for Regex<T>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for
self
and other
) and is used by the <=
operator. Read moreimpl<T: Eq> Eq for Regex<T>
impl<T> StructuralEq for Regex<T>
impl<T> StructuralPartialEq for Regex<T>
Auto Trait Implementations§
impl<T> RefUnwindSafe for Regex<T>where
T: RefUnwindSafe,
impl<T> Send for Regex<T>where
T: Send,
impl<T> Sync for Regex<T>where
T: Sync,
impl<T> Unpin for Regex<T>where
T: Unpin,
impl<T> UnwindSafe for Regex<T>where
T: UnwindSafe,
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more