From 99438e59977ddc5e89fe54ba860e2b248551a72a Mon Sep 17 00:00:00 2001 From: jn Date: Fri, 3 Feb 2023 14:56:07 +0100 Subject: [PATCH] Don't parse _123 as a decimal number Instead require that decimal numbers start with a digit. This fixes the detection of things like _L4 and _4 as labels. --- src/fox32.pest | 4 ++-- src/main.rs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/fox32.pest b/src/fox32.pest index 47022cc..8a9ca4f 100644 --- a/src/fox32.pest +++ b/src/fox32.pest @@ -148,8 +148,8 @@ body_bin = @{ (ASCII_BIN_DIGIT | "_")+ } immediate_hex = ${ "0x" ~ body_hex } body_hex = @{ (ASCII_HEX_DIGIT | "_")+ } -immediate_dec = ${ body_dec } -body_dec = @{ (ASCII_DIGIT | "_")+ } +immediate_dec = ${ ASCII_DIGIT ~ body_dec } +body_dec = @{ (ASCII_DIGIT | "_")* } immediate_char = ${ "'" ~ body_char ~ "'" } body_char = @{ '\x00'..'\x7F' } diff --git a/src/main.rs b/src/main.rs index 31418ea..f6fd1b5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -805,8 +805,8 @@ fn parse_operand(mut pair: pest::iterators::Pair, is_pointer: bool) -> Ast immediate_to_astnode(immediate, size, is_pointer) } Rule::immediate_dec => { - let body_dec_str = operand_value_pair.into_inner().next().unwrap().as_str(); - let immediate = remove_underscores(body_dec_str).parse::().unwrap(); + let dec_str = operand_value_pair.as_span().as_str(); + let immediate = remove_underscores(dec_str).parse::().unwrap(); immediate_to_astnode(immediate, size, is_pointer) } Rule::immediate_char => {