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
//! A library with common code for parsing Minecraft specification.

pub mod parse;
pub mod tokenize;

/// Ensure that the given condition is true, otherwise return the given value.
#[macro_export]
macro_rules! ensure {
    ($cond:expr, $ret:expr) => {
        if !$cond {
            return Err($ret);
        }
    };
}

#[macro_export]
macro_rules! tokenize {
    ($input:expr) => {
        $crate::tokenize::tokenize($input)
            .into_iter()
            .rev()
            .collect()
    };
}

#[cfg(test)]
mod tests {
    #[macro_export]
    macro_rules! test_parse {
        ($tokens:ident, $ty:ty, $value:expr) => {
            assert_eq!(<$ty>::parse(&mut $tokens), $value);
        };
    }
}