fixed bad error positions

This commit is contained in:
afonya2 2025-06-11 15:12:24 +02:00
parent 0e0fee425a
commit b0dca78e04
Signed by: afonya
GPG key ID: EBB9C4CAFAAFB2DC

View file

@ -132,14 +132,14 @@ pub fn create_error(message: &str, position: usize, typ: ErrorType, stype: Error
fn get_exact_pos(file: &String, pos: usize) -> (usize, usize) { fn get_exact_pos(file: &String, pos: usize) -> (usize, usize) {
let mut line = 1; let mut line = 1;
let mut column = 0; let mut column = 1;
for (i, c) in file.char_indices() { for (i, c) in file.chars().enumerate() {
if i == pos { if i == pos-1 {
return (line, column); return (line, column);
} }
if c == '\n' { if c == '\n' {
line += 1; line += 1;
column = 0; column = 1;
} else { } else {
column += 1; column += 1;
} }