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


///  Will return the opposite result of some other parser.
///
/// ## Example
///
/// ```
/// just!( pub plus { "+"; } );
///
/// not!( pub not_a_plus { plus; } );
/// ```
///
#[macro_export]
macro_rules! not {

    ($visibility:vis $name:ident { $parser:ident; }) => {
        
        $visibility fn $name(string: String, index: usize) -> $crate::parse_result::ParseResult {

            use $crate::Progress;
            use $crate::ParseError;
            use $crate::Done;

            let name: &'static str = stringify!($name);

            // Returns a 'Err(ParseError)' if the given parser doesn't fail.
            if let Ok(_) = $parser( string, index ) {
                
                let parse_error = ParseError {

                    offset:0,
                    
                    name_stack: vec![name],
                    
                    message: concat!("'", stringify!($name), "' not allowed.")
                };

                return Err(parse_error);

            }   

            // ... otherwise returns an empty ( but successful ) Progress.
            Ok( Progress { offset: 0, done: Done::Empty() })
 
        }

    };

}