Refine error message.

This commit is contained in:
Stephen Chung 2022-11-27 22:35:17 +08:00
parent fcc7589ffc
commit f458f18ffa
4 changed files with 7 additions and 7 deletions

View File

@ -109,7 +109,7 @@ fn print_error(input: &str, mut err: EvalAltResult) {
// Display position marker
println!(
"\x1b[31m{0:>1$}{err_line}\x1b[39m",
if i > 0 { " " } else { "^ " },
if i > 0 { "| " } else { "^ " },
line_no.len() + pos.position().unwrap() + 1,
);
}

View File

@ -35,7 +35,7 @@ fn print_error(input: &str, mut err: EvalAltResult) {
// Display position marker
println!(
"{0:>1$}{err_line}",
if i > 0 { " " } else { "^ " },
if i > 0 { "| " } else { "^ " },
line_no.len() + pos.position().unwrap() + 1,
);
}

View File

@ -13,7 +13,7 @@ fn eprint_error(input: &str, mut err: EvalAltResult) {
// Display position marker
println!(
"{0:>1$}{err_line}",
if i > 0 { " " } else { "^ " },
if i > 0 { "| " } else { "^ " },
line_no.len() + pos.position().unwrap() + 1,
);
}

View File

@ -135,20 +135,20 @@ impl fmt::Display for EvalAltResult {
#[cfg(not(feature = "no_function"))]
Self::ErrorInFunctionCall(s, src, err, ..) if crate::parser::is_anonymous_fn(s) => {
write!(f, "{err}\n| in closure call")?;
write!(f, "{err}\nin closure call")?;
if !src.is_empty() {
write!(f, " @ '{src}'")?;
}
}
Self::ErrorInFunctionCall(s, src, err, ..) => {
write!(f, "{err}\n| in call to function '{s}'")?;
write!(f, "{err}\nin call to function '{s}'")?;
if !src.is_empty() {
write!(f, " @ '{src}'")?;
}
}
Self::ErrorInModule(s, err, ..) if s.is_empty() => write!(f, "{err}\n| in module")?,
Self::ErrorInModule(s, err, ..) => write!(f, "{err}\n| in module '{s}'")?,
Self::ErrorInModule(s, err, ..) if s.is_empty() => write!(f, "{err}\nin module")?,
Self::ErrorInModule(s, err, ..) => write!(f, "{err}\nin module '{s}'")?,
Self::ErrorVariableExists(s, ..) => write!(f, "Variable already defined: {s}")?,
Self::ErrorForbiddenVariable(s, ..) => write!(f, "Forbidden variable name: {s}")?,