add position annotation to errors
This commit is contained in:
parent
df24b5da84
commit
dc29847cd3
|
@ -21,14 +21,14 @@ pub fn eval_mem(bf_str: &&str, mem: &mut [u8], pointer: &mut usize) -> Result<()
|
|||
|
||||
if char == '>' {
|
||||
if (*pointer) + 1 == 30000 {
|
||||
return Err("Attempt to increase pointer exceeding memory size".into());
|
||||
return Err(format!("Attempt to increase pointer exceeding memory size ({})", pos));
|
||||
}
|
||||
*pointer += 1;
|
||||
continue
|
||||
}
|
||||
if char == '<' {
|
||||
if *pointer == 0 {
|
||||
return Err("Attempt to reduce pointer to less than 1".into());
|
||||
return Err(format!("Attempt to reduce pointer to less than 1 ({})", pos));
|
||||
}
|
||||
*pointer -= 1;
|
||||
continue
|
||||
|
@ -73,7 +73,7 @@ pub fn eval_mem(bf_str: &&str, mem: &mut [u8], pointer: &mut usize) -> Result<()
|
|||
if char == ']' {
|
||||
|
||||
if loop_stack.len() == 0 {
|
||||
return Err(format!("Invalid loop at position {pos}"));
|
||||
return Err(format!("Unmatched ']' ({})", pos));
|
||||
}
|
||||
|
||||
if mem[*pointer] == 0 {
|
||||
|
@ -87,7 +87,7 @@ pub fn eval_mem(bf_str: &&str, mem: &mut [u8], pointer: &mut usize) -> Result<()
|
|||
}
|
||||
|
||||
if loop_stack.len() != 0 {
|
||||
return Err(format!("Unclosed loop at position {}", loop_stack.last().unwrap()));
|
||||
return Err(format!("Unmatched '[' ({})", loop_stack.last().unwrap()));
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
|
Loading…
Reference in New Issue