From 6d151bc2b92663d0a23cba535d59a964826f842a Mon Sep 17 00:00:00 2001 From: russ Date: Tue, 31 Oct 2017 22:10:46 -0700 Subject: [PATCH] minor refactor for sanity --- src/parser.rs | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/src/parser.rs b/src/parser.rs index 9d8b1161..4276bf37 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -370,6 +370,7 @@ impl<'a> TokenIterator<'a> { match c { '0'...'9' => { let mut result = Vec::new(); + let mut radix_base: Option = None; result.push(c); while let Some(&nxt) = self.char_stream.peek() { @@ -403,10 +404,7 @@ impl<'a> TokenIterator<'a> { _ => break, } } - let out: String = result.iter().cloned().skip(2).collect(); - if let Ok(val) = i64::from_str_radix(&out, 16) { - return Some(Token::IntConst(val)); - } + radix_base = Some(16); } 'o' | 'O' => { result.push(nxt); @@ -420,10 +418,7 @@ impl<'a> TokenIterator<'a> { _ => break, } } - let out: String = result.iter().cloned().skip(2).collect(); - if let Ok(val) = i64::from_str_radix(&out, 8) { - return Some(Token::IntConst(val)); - } + radix_base = Some(8); } 'b' | 'B' => { result.push(nxt); @@ -437,15 +432,19 @@ impl<'a> TokenIterator<'a> { _ => break, } } - let out: String = result.iter().cloned().skip(2).filter(|c| c != &'_').collect(); - if let Ok(val) = i64::from_str_radix(&out, 2) { - return Some(Token::IntConst(val)); - } + radix_base = Some(2); } _ => break, } } + if let Some(radix) = radix_base { + let out: String = result.iter().cloned().skip(2).filter(|c| c != &'_').collect(); + if let Ok(val) = i64::from_str_radix(&out, radix) { + return Some(Token::IntConst(val)); + } + } + let out: String = result.iter().cloned().collect(); if let Ok(val) = out.parse::() {