Skip to content
This repository has been archived by the owner on Jan 10, 2025. It is now read-only.

Commit

Permalink
Accept spaces between register and offset (#572)
Browse files Browse the repository at this point in the history
  • Loading branch information
LucasSte authored May 26, 2024
1 parent 4261c25 commit c478374
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/asm_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ parser! {

parser! {
fn integer[I]()(I) -> i64 where [I: Stream<Item=char>] {
let sign = optional(one_of("-+".chars())).map(|x| match x {
let sign = optional(one_of("-+".chars()).skip(skip_many(char(' ')))).map(|x| match x {
Some('-') => -1,
_ => 1,
});
Expand Down Expand Up @@ -92,7 +92,7 @@ parser! {
let memory = between(
char('['),
char(']'),
(register(), optional(integer())),
(register().skip(skip_many(char(' '))), optional(integer())),
)
.map(|t| Operand::Memory(t.0, t.1.unwrap_or(0)));
let label = ident().map(Operand::Label);
Expand Down Expand Up @@ -239,6 +239,11 @@ mod tests {
operand().parse("[r3-0x1f]"),
Ok((Operand::Memory(3, -31), ""))
);
assert_eq!(operand().parse("[r5 + 3]"), Ok((Operand::Memory(5, 3), "")));
assert_eq!(
operand().parse("[r11 - 0x30]"),
Ok((Operand::Memory(11, -48), ""))
);
}

#[test]
Expand Down

0 comments on commit c478374

Please sign in to comment.