summaryrefslogtreecommitdiffstats
path: root/third_party/rust/weedle2/src/whitespace.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
commit26a029d407be480d791972afb5975cf62c9360a6 (patch)
treef435a8308119effd964b339f76abb83a57c29483 /third_party/rust/weedle2/src/whitespace.rs
parentInitial commit. (diff)
downloadfirefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz
firefox-26a029d407be480d791972afb5975cf62c9360a6.zip
Adding upstream version 124.0.1.upstream/124.0.1
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.rs34
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)
+}