Skip to content

Commit

Permalink
Merge pull request #31 from rozukke/fix/hexlike-labels
Browse files Browse the repository at this point in the history
Fix labels that look like hex erroring
  • Loading branch information
rozukke authored Sep 20, 2024
2 parents 0d82fe9 + 8cc3bb3 commit e598bdf
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions src/lexer/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::fmt::Display;
use std::num::IntErrorKind;
use std::str::FromStr;
use std::{i16, u16};

Expand Down Expand Up @@ -199,13 +200,16 @@ impl Cursor<'_> {
let str_val = self.get_range(start..self.abs_pos());
let value = match u16::from_str_radix(str_val, 16) {
Ok(value) => value,
Err(e) => {
return Err(error::lex_invalid_lit(
(start - prefix..self.abs_pos()).into(),
self.src(),
e,
))
}
Err(e) => match e.kind() {
IntErrorKind::PosOverflow => {
return Err(error::lex_invalid_lit(
(start - prefix..self.abs_pos()).into(),
self.src(),
e,
));
}
_ => return Ok(self.ident()),
},
};

Ok(TokenKind::Lit(LiteralKind::Hex(value)))
Expand Down Expand Up @@ -388,6 +392,13 @@ mod test {
assert!(res.kind == TokenKind::Lit(LiteralKind::Hex(0x3000)))
}

#[test]
fn hex_not_num() {
let mut lex = Cursor::new("X_S");
let res = lex.advance_token().unwrap();
assert_eq!(res.kind, TokenKind::Label)
}

// DEC LIT TESTS

#[test]
Expand Down

0 comments on commit e598bdf

Please sign in to comment.