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
use crate::IResult;

pub(crate) fn sp(input: &str) -> IResult<&str, &str> {
    recognize!(
        input,
        many0!(alt!(
            // ignores line comments
            do_parse!(tag!("//") >> take_until!("\n") >> char!('\n') >> (()))
            |
            // ignores whitespace
            map!(take_while1!(|c| c == '\t' || c == '\n' || c == '\r' || c == ' '), |_| ())
            |
            // ignores block comments
            do_parse!(tag!("/*") >> take_until!("*/") >> tag!("*/") >> (()))
        ))
    )
}

/// ws! also ignores line & block comments
macro_rules! ws (
    ($i:expr, $($args:tt)*) => ({
        use $crate::whitespace::sp;

        do_parse!($i,
            sp >>
            s: $($args)* >>
            sp >>
            (s)
        )
    });
);