From 242cd7857ff3bb1911670a2634a4abb9a5651611 Mon Sep 17 00:00:00 2001 From: ConnorSkees <39542938+ConnorSkees@users.noreply.github.com> Date: Sun, 22 Mar 2020 00:41:31 -0400 Subject: [PATCH] handle error case in lexing --- src/lexer.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/lexer.rs b/src/lexer.rs index 6eef5ea..2beb858 100644 --- a/src/lexer.rs +++ b/src/lexer.rs @@ -48,6 +48,7 @@ impl<'a> Iterator for Lexer<'a> { s.push_str(&n); TokenKind::Number(s) } + e @ TokenKind::Error(..) => e, _ => unsafe { std::hint::unreachable_unchecked() }, }, 'a'..='z' | 'A'..='Z' | '_' | '-' => match self.lex_ident() { @@ -62,6 +63,7 @@ impl<'a> Iterator for Lexer<'a> { TokenKind::Ident(s) } TokenKind::Symbol(Symbol::Minus) => TokenKind::Ident(String::from("--")), + e @ TokenKind::Error(..) => e, _ => unsafe { std::hint::unreachable_unchecked() }, }, _ => TokenKind::Symbol(Symbol::Minus), @@ -79,6 +81,7 @@ impl<'a> Iterator for Lexer<'a> { s.push_str(&n); TokenKind::Number(s) } + e @ TokenKind::Error(..) => e, _ => unsafe { std::hint::unreachable_unchecked() }, }, _ => TokenKind::Symbol(Symbol::Period),