Refine error display.

This commit is contained in:
Stephen Chung
2022-11-27 18:00:02 +08:00
parent 549193f49b
commit fcc7589ffc
7 changed files with 82 additions and 93 deletions

View File

@@ -31,12 +31,14 @@ fn print_error(input: &str, mut err: EvalAltResult) {
// Specific position - print line text
println!("{line_no}{}", lines[pos.line().unwrap() - 1]);
// Display position marker
println!(
"{0:>1$} {err}",
"^",
line_no.len() + pos.position().unwrap(),
);
for (i, err_line) in err.to_string().split('\n').enumerate() {
// Display position marker
println!(
"{0:>1$}{err_line}",
if i > 0 { " " } else { "^ " },
line_no.len() + pos.position().unwrap() + 1,
);
}
}
}