fixed bad error positions
This commit is contained in:
parent
0e0fee425a
commit
b0dca78e04
1 changed files with 4 additions and 4 deletions
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue