Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Nom: Fix for many1 not propagating incomplete state
diff --git a/src/macros.rs b/src/macros.rs
index 7ea9fbd..607ab25 100644
--- a/src/macros.rs
+++ b/src/macros.rs
@@ -1712,14 +1712,27 @@ macro_rules! many1(
{
let mut res = Vec::new();
let mut input = $i;
- while let $crate::IResult::Done(i,o) = $submac!(input, $($args)*) {
- if i.len() == input.len() {
- break;
+ let mut incomplete = None;
+ loop {
+ match $submac!(input, $($args)*) {
+ $crate::IResult::Done(i,o) => {
+ if i.len() == input.len() {
+ break;
+ }
+ res.push(o);
+ input = i;
+ },
+ $crate::IResult::Incomplete(n) => {
+ incomplete = Some(n);
+
+ break
+ },
+ _ => break,
}
- res.push(o);
- input = i;
}
- if res.is_empty() {
+ if let Some(n) = incomplete {
+ $crate::IResult::Incomplete(n)
+ } else if res.is_empty() {
$crate::IResult::Error($crate::Err::Position($crate::ErrorKind::Many1,$i))
} else {
$crate::IResult::Done(input, res)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment