Created
November 27, 2015 16:42
-
-
Save m4rw3r/e7018d0b9689530c18f7 to your computer and use it in GitHub Desktop.
Nom: Fix for many1 not propagating incomplete state
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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