Skip to content

Commit

Permalink
fix: handle invalid tokens better
Browse files Browse the repository at this point in the history
  • Loading branch information
dxrcy committed Dec 4, 2024
1 parent 00fbfb4 commit 7826f7f
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,6 @@ fn preprocess_simple(src: &'static str) -> Result<Vec<Token>> {
loop {
let token = cur.advance_real()?;
match token.kind {
TokenKind::Dir(_) => {
return Err(error::parse_generic_unexpected(src, "instruction", token));
}

TokenKind::Byte(_) => unreachable!("Found byte in stream"),
TokenKind::Breakpoint => unreachable!("Found breakpoint in stream"),
TokenKind::Comment | TokenKind::Whitespace => continue,
Expand Down Expand Up @@ -242,19 +238,25 @@ impl AsmParser {
TokenKind::Instr(instr_kind) => self.parse_instr(instr_kind),
TokenKind::Trap(trap_kind) => self.parse_trap(trap_kind),

TokenKind::Dir(_) | TokenKind::Label | TokenKind::Lit(_) | TokenKind::Reg(_) => {
return Err(error::parse_generic_unexpected(
self.src,
"instruction",
tok,
))
}

// Does not exist in preprocessed token stream
TokenKind::Comment
| TokenKind::Whitespace
| TokenKind::Eof
| TokenKind::Dir(_)
| TokenKind::Label
| TokenKind::Lit(_)
| TokenKind::Reg(_)
| TokenKind::Byte(_)
| TokenKind::Breakpoint => {
unreachable!("Found invalid token kind in preprocessed stream");
}
}

// TODO(fix): Check for end of line here
}

/// Return label or leave iter untouched and return None
Expand Down

0 comments on commit 7826f7f

Please sign in to comment.