Skip to content

Commit

Permalink
Appease clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
zesterer committed Jan 1, 2024
1 parent d3a2667 commit a589f08
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 11 deletions.
17 changes: 13 additions & 4 deletions src/combinator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2068,7 +2068,7 @@ where
Ok(item) => {
*finished = true;
Ok(Some(item))
},
}
Err(()) => {
inp.rewind(before);
*finished = true;
Expand Down Expand Up @@ -2169,23 +2169,32 @@ where
inp: &mut InputRef<'a, '_, I, E>,
(st, iter): &mut Self::IterState<M>,
) -> IPResult<M, O::Item> {
if let Some(item) = iter.as_mut().and_then(|i| M::get_or(M::map(M::from_mut(i), |i| i.next()), || None)) {
if let Some(item) = iter
.as_mut()
.and_then(|i| M::get_or(M::map(M::from_mut(i), |i| i.next()), || None))
{
return Ok(Some(M::bind(move || item)));
}

// TODO: Debug looping check
loop {
let before = inp.save();
match self.parser.next::<M>(inp, st) {
Ok(Some(item)) => match M::get_or(M::map(M::from_mut(iter.insert(M::map(item, |i| i.into_iter()))), |i| i.next().map(Some)), || Some(None)) {
Ok(Some(item)) => match M::get_or(
M::map(
M::from_mut(iter.insert(M::map(item, |i| i.into_iter()))),
|i| i.next().map(Some),
),
|| Some(None),
) {
Some(Some(item)) => break Ok(Some(M::bind(move || item))),
Some(None) => break Ok(Some(M::bind(|| unreachable!()))),
None => continue,
},
Ok(None) => break Ok(None),
Err(()) => {
inp.rewind(before);
break Err(())
break Err(());
}
}
}
Expand Down
14 changes: 11 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2505,7 +2505,10 @@ where
O: IntoIterator,
Self: Sized,
{
Flatten { parser: self, phantom: EmptyPhantom::new() }
Flatten {
parser: self,
phantom: EmptyPhantom::new(),
}
}

/// Create an iterator over the outputs generated by an iterable parser.
Expand Down Expand Up @@ -3422,10 +3425,12 @@ mod tests {
assert_eq!(parser().parse("aaa").into_result(), Ok(()));
}

#[cfg(feature = "nightly")]
#[test]
fn flatten() {
fn parser<'a>() -> impl Parser<'a, &'a str, Vec<char>, extra::Err<MyErr>> {
let many_as = just('a').map(Some)
let many_as = just('a')
.map(Some)
.or(any().to(None))
.repeated()
.flatten()
Expand All @@ -3434,7 +3439,10 @@ mod tests {
many_as.into_iter().collect()
}

assert_eq!(parser().parse("abracadabra").into_result(), Ok(vec!['a', 'a', 'a', 'a', 'a']));
assert_eq!(
parser().parse("abracadabra").into_result(),
Ok(vec!['a', 'a', 'a', 'a', 'a'])
);
}

#[test]
Expand Down
14 changes: 10 additions & 4 deletions src/private.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,13 @@ impl Mode for Emit {
}

#[inline(always)]
fn from_mut<T>(r: &mut Self::Output<T>) -> Self::Output<&mut T> { r }
fn from_mut<T>(r: &mut Self::Output<T>) -> Self::Output<&mut T> {
r
}
#[inline(always)]
fn get_or<T, F: FnOnce() -> T>(r: Self::Output<T>, f: F) -> T { r }
fn get_or<T, F: FnOnce() -> T>(r: Self::Output<T>, _f: F) -> T {
r
}

#[inline(always)]
fn invoke<'a, I, O, E, P>(parser: &P, inp: &mut InputRef<'a, '_, I, E>) -> PResult<Self, O>
Expand Down Expand Up @@ -174,9 +178,11 @@ impl Mode for Check {
#[inline(always)]
fn array<T, const N: usize>(_: [Self::Output<T>; N]) -> Self::Output<[T; N]> {}
#[inline(always)]
fn from_mut<T>(r: &mut Self::Output<T>) -> Self::Output<&mut T> {}
fn from_mut<T>(_r: &mut Self::Output<T>) -> Self::Output<&mut T> {}
#[inline(always)]
fn get_or<T, F: FnOnce() -> T>(r: Self::Output<T>, f: F) -> T { f() }
fn get_or<T, F: FnOnce() -> T>(_r: Self::Output<T>, f: F) -> T {
f()
}

#[inline(always)]
fn invoke<'a, I, O, E, P>(parser: &P, inp: &mut InputRef<'a, '_, I, E>) -> PResult<Self, O>
Expand Down

0 comments on commit a589f08

Please sign in to comment.