diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /third_party/rust/weedle2/src/whitespace.rs | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/rust/weedle2/src/whitespace.rs')
-rw-r--r-- | third_party/rust/weedle2/src/whitespace.rs | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/third_party/rust/weedle2/src/whitespace.rs b/third_party/rust/weedle2/src/whitespace.rs new file mode 100644 index 0000000000..336e4784e1 --- /dev/null +++ b/third_party/rust/weedle2/src/whitespace.rs @@ -0,0 +1,34 @@ +use nom::{IResult, Parser}; + +pub(crate) fn sp(input: &str) -> IResult<&str, &str> { + nom::combinator::recognize(nom::multi::many0(nom::branch::alt(( + // ignores line comments + nom::combinator::value( + (), + nom::sequence::tuple(( + nom::bytes::complete::tag("//"), + nom::bytes::complete::take_until("\n"), + nom::bytes::complete::tag("\n"), + )), + ), + // ignores whitespace + nom::combinator::value((), nom::character::complete::multispace1), + // ignores block comments + nom::combinator::value( + (), + nom::sequence::tuple(( + nom::bytes::complete::tag("/*"), + nom::bytes::complete::take_until("*/"), + nom::bytes::complete::tag("*/"), + )), + ), + ))))(input) +} + +/// ws also ignores line & block comments +pub(crate) fn ws<'a, F>(inner: F) -> impl FnMut(&'a str) -> IResult<&str, &str> +where + F: Parser<&'a str, &'a str, nom::error::Error<&'a str>>, +{ + nom::sequence::delimited(sp, inner, sp) +} |