regular_expression_bootstrap/
lib.rs

1use std::ops::AddAssign;
2use num::{
3    Bounded,
4    One,
5};
6
7#[macro_use]
8mod util;
9mod regular_expression;
10
11pub use crate::regular_expression::{
12    Expression,
13    Re,
14};
15
16pub trait StateGenerator {
17    type State;
18
19    fn next_initial(&mut self) -> Self::State;
20    fn next_final(&mut self) -> Self::State;
21    fn disable_final(&mut self) -> &mut Self;
22    fn enable_final(&mut self) -> &mut Self;
23}
24
25struct SimpleStateGenerator<S> {
26    state: S,
27}
28
29impl<S: Bounded> SimpleStateGenerator<S> {
30    pub fn new() -> SimpleStateGenerator<S> {
31        SimpleStateGenerator { state: S::min_value() }
32    }
33}
34
35impl<S: AddAssign + Copy + One> StateGenerator for SimpleStateGenerator<S> {
36    type State = S;
37
38    fn next_initial(&mut self) -> S {
39        let state = self.state;
40        self.state += S::one();
41        state
42    }
43
44    fn next_final(&mut self) -> S {
45        let state = self.state;
46        self.state += S::one();
47        state
48    }
49
50    fn disable_final(&mut self) -> &mut SimpleStateGenerator<S> {
51        self
52    }
53
54    fn enable_final(&mut self) -> &mut SimpleStateGenerator<S> {
55        self
56    }
57}
58