Skip to content

Commit

Permalink
use workaround for improper Ctrl-D behavior resulting from peek() rem…
Browse files Browse the repository at this point in the history
…oval
  • Loading branch information
mthom committed Aug 3, 2020
1 parent f26b66d commit bafe26d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "prolog_parser"
version = "0.8.64"
version = "0.8.65"
authors = ["Mark Thom <[email protected]>"]
repository = "https://github.com/mthom/prolog_parser"
description = " An operator precedence parser for rusty-wam, an up and coming ISO Prolog implementation."
Expand Down
23 changes: 12 additions & 11 deletions src/put_back_n.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
use std::iter::Peekable;

#[derive(Debug, Clone)]
pub struct PutBackN<I: Iterator> {
top: Vec<I::Item>,
iter: I,
iter: Peekable<I>,
}

pub fn put_back_n<I>(iterable: I) -> PutBackN<I::IntoIter>
where I: IntoIterator
{
PutBackN {
top: Vec::new(),
iter: iterable.into_iter(),
iter: iterable.into_iter().peekable(),
}
}

Expand All @@ -26,19 +27,19 @@ impl<I: Iterator> PutBackN<I> {
std::mem::replace(&mut self.top, vec![])
}

#[inline]
pub fn take_iter_mut(&mut self) -> &mut I {
&mut self.iter
}

#[inline]
pub(crate)
fn peek(&mut self) -> Option<&I::Item> {
if self.top.is_empty() {
match self.iter.next() {
Some(item) => {
self.top.push(item);
self.top.last()
/* This is a kludge for Ctrl-D not being
* handled properly if self.iter().peek() isn't called
* first. */
match self.iter.peek() {
Some(_) => {
self.iter.next().and_then(move |item| {
self.top.push(item);
self.top.last()
})
}
None => {
None
Expand Down

0 comments on commit bafe26d

Please sign in to comment.