Skip to content
This repository has been archived by the owner on Jun 3, 2021. It is now read-only.

Give a better panic message when unput is buggy #362

Merged
merged 1 commit into from
Mar 30, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/lex/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,13 @@ impl Lexer {
/// This function will panic if called twice in a row
/// or when `self.lookahead.is_some()`.
fn unput(&mut self, byte: u8) {
assert!(self.lookahead.is_none());
assert!(
self.lookahead.is_none(),
"unputting {:?} would cause the lexer to forget it saw {:?} (current is {:?})",
byte as char,
self.lookahead.unwrap() as char,
self.current.unwrap() as char
);
self.lookahead = self.current.take();
self.current = Some(byte);
// TODO: this is not right,
Expand Down