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

@@ -8,11 +8,15 @@ fn eprint_error(input: &str, mut err: EvalAltResult) {
let line_no = format!("{line}: ");
eprintln!("{line_no}{}", lines[line - 1]);
eprintln!(
"{:>1$} {err_msg}",
"^",
line_no.len() + pos.position().unwrap(),
);
for (i, err_line) in err_msg.to_string().split('\n').enumerate() {
// Display position marker
println!(
"{0:>1$}{err_line}",
if i > 0 { " " } else { "^ " },
line_no.len() + pos.position().unwrap() + 1,
);
}
eprintln!();
}