Skip to content

Commit

Permalink
fix(parse): report entire erroneous token
Browse files Browse the repository at this point in the history
  • Loading branch information
dxrcy committed Jan 27, 2025
1 parent 7ba9481 commit 74c2a9b
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/debugger/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,18 @@ impl<'a> CommandIter<'a> {
Some(next)
}

/// Increment head past all remaing characters in the argument (i.e. until whitespace).
///
/// Used to get entire argument for diagnosis.
fn next_end_of_argument(&mut self) {
while let Some(_) = self.peek() {
if self.is_end_of_argument() {
break;
}
self.next();
}
}

/// Get characters between base..head, WITHOUT updating base.
fn get(&self) -> &str {
assert!(self.base <= self.head, "base exceeded head");
Expand Down Expand Up @@ -573,6 +585,17 @@ impl<'a> CommandIter<'a> {
/// - Multiple zeros before radix prefix. Eg. `00x4`.
/// - Absolute value out of bounds for `i32`. (Does *NOT* check if integer fits in specific bit size).
fn next_integer_token(&mut self, require_sign: bool) -> Result<Option<i32>, error::Value> {
self.next_integer_token_inner(require_sign)
.map_err(|error| {
self.next_end_of_argument();
error
})
}

fn next_integer_token_inner(
&mut self,
require_sign: bool,
) -> Result<Option<i32>, error::Value> {
self.reset_head();
// Don't skip whitespace

Expand Down Expand Up @@ -755,6 +778,7 @@ impl<'a> CommandIter<'a> {
let offset = int_as_i16(self.next_integer_token(true)?.unwrap_or(0))?;

if !self.is_end_of_argument() {
self.next_end_of_argument();
return Err(error::Value::MalformedLabel {});
}
self.set_base();
Expand Down

0 comments on commit 74c2a9b

Please sign in to comment.