Skip to content

Commit

Permalink
Eliminate eof token state
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Jan 7, 2022
1 parent bb85c61 commit fcb5968
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 21 deletions.
15 changes: 1 addition & 14 deletions src/algorithm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ pub enum Token {
Break(BreakToken),
Begin(BeginToken),
End,
Eof,
}

#[derive(Copy, Clone)]
Expand Down Expand Up @@ -83,27 +82,16 @@ struct BufEntry {
size: isize,
}

impl Default for BufEntry {
fn default() -> Self {
BufEntry {
token: Token::Eof,
size: 0,
}
}
}

impl Printer {
pub fn new() -> Self {
let linewidth = 78;
let mut buf = RingBuffer::new();
buf.advance_right();
Printer {
out: String::new(),
margin: linewidth as isize,
space: linewidth as isize,
left: 0,
right: 0,
buf,
buf: RingBuffer::new(),
left_total: 0,
right_total: 0,
scan_stack: VecDeque::new(),
Expand Down Expand Up @@ -344,7 +332,6 @@ impl Printer {
assert_eq!(len, l);
self.print_string(s);
}
Token::Eof => panic!(), // Eof should never get here.
}
}
}
7 changes: 0 additions & 7 deletions src/ring.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,6 @@ impl<T> RingBuffer<T> {
self.data.push_back(value);
}

pub fn advance_right(&mut self)
where
T: Default,
{
self.data.push_back(T::default());
}

pub fn advance_left(&mut self) {
self.data.pop_front().unwrap();
self.offset += 1;
Expand Down

0 comments on commit fcb5968

Please sign in to comment.