Skip to content

Commit

Permalink
asm: Use match statements to clarify parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
Granddave committed Jul 14, 2024
1 parent 1ee860f commit c1dac97
Showing 1 changed file with 21 additions and 23 deletions.
44 changes: 21 additions & 23 deletions src/assembler/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -353,20 +353,20 @@ impl<'a> Parser<'a> {
if !self.peek_token_is(0, TokenType::Comma) {
return Err(invalid_token!(
self,
"invalid indirect indexed Y operand, expected ','"
"Invalid indirect indexed Y operand, expected ','"
));
}
self.next_token()?; // Consume the closing parenthesis
self.next_token()?; // Consume the comma
match self.current_token.lexeme.to_uppercase().as_str() {
"Y" => Ok((
AddressingMode::IndirectIndexedY,
if let Some(byte) = byte {
Operand::ZeroPage(byte)
} else if let Some(identifier) = identifier {
Operand::Constant(identifier)
} else {
return Err(invalid_token!(self, "invalid indirect indexed Y operand"));
match (byte, identifier) {
(Some(byte), None) => Operand::ZeroPage(byte),
(None, Some(identifier)) => Operand::Constant(identifier),
(_, _) => {
return Err(invalid_token!(self, "Invalid indirect indexed Y operand"))
}
},
)),
_ => Err(invalid_token!(
Expand All @@ -390,22 +390,20 @@ impl<'a> Parser<'a> {
return Ok(None);
}

if self.peek_token_is(0, TokenType::Comma)
&& self.peek_token_is(1, TokenType::Identifier /* X */)
{
// (u8,X)
Ok(Some(
self.parse_indirect_indexed_x(byte, constant_identifier)?,
))
} else if self.peek_token_is(0, TokenType::ParenRight)
&& self.peek_token_is(1, TokenType::Comma)
{
// (u8),Y
Ok(Some(
self.parse_indirect_indexed_y(byte, constant_identifier)?,
))
} else {
Ok(None)
match (self.peek_token(0).token, self.peek_token(1).token) {
(TokenType::Comma, TokenType::Identifier) => {
// (u8,X)
Ok(Some(
self.parse_indirect_indexed_x(byte, constant_identifier)?,
))
}
(TokenType::ParenRight, TokenType::Comma) => {
// (u8),Y
Ok(Some(
self.parse_indirect_indexed_y(byte, constant_identifier)?,
))
}
(_, _) => Ok(None),
}
}

Expand Down

0 comments on commit c1dac97

Please sign in to comment.