From c478374a5422d6c7767622c08993f4444b561638 Mon Sep 17 00:00:00 2001 From: Lucas Ste <38472950+LucasSte@users.noreply.github.com> Date: Sun, 26 May 2024 09:57:27 -0500 Subject: [PATCH] Accept spaces between register and offset (#572) --- src/asm_parser.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/asm_parser.rs b/src/asm_parser.rs index 391d4f66..97f9ad54 100644 --- a/src/asm_parser.rs +++ b/src/asm_parser.rs @@ -64,7 +64,7 @@ parser! { parser! { fn integer[I]()(I) -> i64 where [I: Stream] { - 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, }); @@ -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); @@ -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]