1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
use std::ops::AddAssign;
use num::{
    Bounded,
    One,
};

#[macro_use]
mod util;
mod regular_expression;

pub use crate::regular_expression::{
    Expression,
    Re,
};

pub trait StateGenerator {
    type State;

    fn next_initial(&mut self) -> Self::State;
    fn next_final(&mut self) -> Self::State;
    fn disable_final(&mut self) -> &mut Self;
    fn enable_final(&mut self) -> &mut Self;
}

struct SimpleStateGenerator<S> {
    state: S,
}

impl<S: Bounded> SimpleStateGenerator<S> {
    pub fn new() -> SimpleStateGenerator<S> {
        SimpleStateGenerator { state: S::min_value() }
    }
}

impl<S: AddAssign + Copy + One> StateGenerator for SimpleStateGenerator<S> {
    type State = S;

    fn next_initial(&mut self) -> S {
        let state = self.state;
        self.state += S::one();
        state
    }

    fn next_final(&mut self) -> S {
        let state = self.state;
        self.state += S::one();
        state
    }

    fn disable_final(&mut self) -> &mut SimpleStateGenerator<S> {
        self
    }

    fn enable_final(&mut self) -> &mut SimpleStateGenerator<S> {
        self
    }
}