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

Commit

Permalink
Give a better panic message when unput is buggy
Browse files Browse the repository at this point in the history
  • Loading branch information
jyn514 authored and Joshua Nelson committed Mar 30, 2020
1 parent c7f7928 commit 7419ac3
Showing 1 changed file with 7 additions and 1 deletion.
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

0 comments on commit 7419ac3

Please sign in to comment.