Skip to content

Instantly share code, notes, and snippets.

@alejandrolechuga
Created June 1, 2019 00:03
Show Gist options
  • Save alejandrolechuga/2432f48b129026692f98ae5417b64eb7 to your computer and use it in GitHub Desktop.
Save alejandrolechuga/2432f48b129026692f98ae5417b64eb7 to your computer and use it in GitHub Desktop.
diff --git a/lexer/src/lib.rs b/lexer/src/lib.rs
index 45d6b38..88495f9 100644
--- a/lexer/src/lib.rs
+++ b/lexer/src/lib.rs
@@ -163,11 +163,22 @@ where I: Iterator<Item = char>,
// matches constructs beginning with a digit, e.g. 0.123 or 10e+42
fn digit(&mut self) -> Result<TokenType, LexError> {
let mut s = String::new();
+ // is digit 0
+ // is the next thing x
+ // next thing should hex digits
+ match self.peek() {
+ Some(c) if c == 'x'|| c == 'X' => {
+ s.push(c);
+ return Ok(TokenType::Number(s));
+ },
+ None => return Err(self.unexpected_eof()),
+ Some(_) => ()
+ }
// integer part
self.push_while(&mut s, is_digit);
- // decmal part
+ // decimal part
if let Some('.') = self.peek() {
match self.decimal() {
Ok(d) => s.push_str(&d),
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment