1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
/// Macro to avoid repetition in the Lexer::next_token() method.
///
/// IMPORTANT: The array of expectations need to be ordered from the largest to
/// the shortest string.
#[macro_export]
macro_rules! match_any_or_syntax_error {
    ($lexer: expr, $expectations: expr, $kind: expr) => {{
        let expect = $expectations;

        if let Some(iff) = expect.iter().find(|m| $lexer.next_matches(m)) {
            $lexer.skip(iff.len());
            $kind
        }
        else {
            return Err(
                LexerError::SyntaxError(
                    format!("expected one of the following: {}", expect.iter().map(|s| format!("'{}'", s)).collect::<Vec<String>>().join(", ")),
                    ($lexer.pos, $lexer.pos + 1).into()
                )
            )
        }
    }
    };
}