Repository: Marwes/combine (language: rust)

Issue:
sep_end_by(1) can eat separator at the end twice
I don't think this was intentional:
```rust
    let mut parser = sep_end_by1(digit(), token(';'));
    assert_eq!(parser.parse("1;;"), Ok((vec!['1'], ";")));
    // thread 'main' panicked at 'assertion failed: `(left == right)`
    //  left: `Ok((['1'], ""))`,
    //  right: `Ok((['1'], ";"))`'
```


Discussion / hints:

Fix patch:
diff --git a/src/combinator.rs b/src/combinator.rs
index 040fde23..9bbba369 100644
--- a/src/combinator.rs
+++ b/src/combinator.rs
@@ -1591,12 +1591,10 @@ where
         input.combine_consumed(|input| {
             let rest = (&mut self.separator).with(optional(&mut self.parser));
             let mut iter = Iter::new(rest, input);
-            // `iter` yields Option<P::Output>, by using flat map we make sure that we stop
-            // iterating once a None element is received, i.e `self.parser` did not parse
-            // successfully
             let result = Some(first)
                 .into_iter()
-                .chain(iter.by_ref().flat_map(|x| x))
+                // Parse elements until `self.parser` returns `None`
+                .chain(iter.by_ref().scan((), |_, x| x))
                 .collect();
             iter.into_result_fast(result)
         })
@@ -3107,4 +3105,10 @@ mod tests {
         assert_eq!(parser.parse("aa"), Ok(("a", "a")));
         assert!(parser.parse("aaa").is_err());
     }
+
+    #[test]
+    fn sep_end_by1_dont_eat_separator_twice() {
+        let mut parser = sep_end_by1(digit(), token(';'));
+        assert_eq!(parser.parse("1;;"), Ok((vec!['1'], ";")));
+    }
 }


Test patch: