Skip to content

Instantly share code, notes, and snippets.

@m4rw3r
Created November 27, 2015 16:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save m4rw3r/e7018d0b9689530c18f7 to your computer and use it in GitHub Desktop.
Save m4rw3r/e7018d0b9689530c18f7 to your computer and use it in GitHub Desktop.
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