Skip to main content

c_lexer_stable/
macros.rs

1#[cfg(test)]
2macro_rules! should {
3    ($name:ident, $left:expr, $right:expr) => {
4        #[test]
5        fn $name() {
6            use crate::Lexer;
7
8            let input = &$left[..];
9            let result = Lexer::lex(input).unwrap();
10            assert_eq!(result, $right);
11        }
12    };
13}
14
15macro_rules! accept_state {
16    ($name:ident) => {
17        #[derive(Debug)]
18        pub struct $name;
19        impl State for $name {
20            fn is_final(&self) -> bool {
21                true
22            }
23        }
24    };
25}
26
27macro_rules! state {
28    ($name:ident) => {
29        #[derive(Debug)]
30        pub struct $name;
31        impl State for $name {
32            fn is_final(&self) -> bool {
33                false
34            }
35        }
36    };
37}
38
39macro_rules! edge {
40    ($from:ty, $to:ident) => {
41        impl From<StateMachine<$from>> for StateMachine<$to> {
42            fn from(_st: StateMachine<$from>) -> Self {
43                StateMachine { state: $to }
44            }
45        }
46    };
47}