summaryrefslogtreecommitdiffstats
path: root/third_party/rust/weedle2/src/whitespace.rs
diff options
context:
space:
mode:
Diffstat (limited to '')
-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)
+}