Debian Codegraph @

third_party/rust/weedle2/src/whitespace.rs

raw
1 use nom::{IResult, Parser};
2
3 pub(crate) fn sp(input: &str) -> IResult<&str, &str> {
4 nom::combinator::recognize(nom::multi::many0(nom::branch::alt((
5 // ignores line comments
6 nom::combinator::value(
7 (),
8 nom::sequence::tuple((
9 nom::bytes::complete::tag("//"),
10 nom::combinator::not(nom::bytes::complete::tag("/")),
11 nom::bytes::complete::take_until("\n"),
12 nom::bytes::complete::tag("\n"),
13 )),
14 ),
15 // ignores whitespace
16 nom::combinator::value((), nom::character::complete::multispace1),
17 // ignores block comments
18 nom::combinator::value(
19 (),
20 nom::sequence::tuple((
21 nom::bytes::complete::tag("/*"),
22 nom::bytes::complete::take_until("*/"),
23 nom::bytes::complete::tag("*/"),
24 )),
25 ),
26 ))))(input)
27 }
28
29 /// ws also ignores line & block comments
30 pub(crate) fn ws<'a, F>(inner: F) -> impl FnMut(&'a str) -> IResult<&str, &str>
31 where
32 F: Parser<&'a str, &'a str, nom::error::Error<&'a str>>,
33 {
34 nom::sequence::delimited(sp, inner, sp)
35 }