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
#[macro_export]
macro_rules! automaton {
    ( $( $token:tt )* ) => {
        {
            let mut automaton = Automaton::new();
            automaton_items!(automaton $( $token )*);
            automaton
        }
    }
}

#[macro_export]
macro_rules! automaton_items {
    ( $aut:ident $f:tt ( $( $sub:expr ),* ) -> $q:tt, $( $token:tt )* ) => {
        let mut subs = Vec::new();
        $(
            subs.push($sub.clone());
        )*
        $aut.add(Configuration($f.clone(), subs), NoLabel, $q);
        automaton_items!($aut $( $token )*)
    };
    ( $aut:ident $f:tt -> $q:tt, $( $token:tt )* ) => {
        $aut.add(Configuration($f.clone(), Vec::new()), NoLabel, $q);
        automaton_items!($aut $( $token )*)
    };
    ( $aut:ident finals $($q:tt)* ) => {
        $(
            $aut.set_final($q);
        )*
    }
}