Rewrite punct macro in Rust
diff --git a/src/helper.rs b/src/helper.rs
index eec26d6..a97fbee 100644
--- a/src/helper.rs
+++ b/src/helper.rs
@@ -4,10 +4,25 @@
macro_rules! punct {
($i:expr, $punct:expr) => {
- complete!($i, preceded!(opt!(call!(::nom::multispace)), tag_s!($punct)))
+ $crate::helper::punct($i, $punct)
};
}
+pub fn punct<'a>(input: &'a str, token: &'static str) -> IResult<&'a str, &'a str> {
+ let mut chars = input.char_indices();
+ while let Some((i, ch)) = chars.next() {
+ if !ch.is_whitespace() {
+ return if input[i..].starts_with(token) {
+ let end = i + token.len();
+ IResult::Done(&input[end..], &input[i..end])
+ } else {
+ IResult::Error(nom::Err::Position(nom::ErrorKind::TagStr, input))
+ };
+ }
+ }
+ IResult::Error(nom::Err::Position(nom::ErrorKind::TagStr, input))
+}
+
macro_rules! option (
($i:expr, $submac:ident!( $($args:tt)* )) => ({
match $submac!($i, $($args)*) {