mirror of
https://github.com/RustPython/Parser.git
synced 2025-09-11 04:46:17 +00:00
Fix caret diagnostics for mutiple lines
This commit is contained in:
parent
28fbdffdc8
commit
aff1a6d53c
1 changed files with 10 additions and 11 deletions
17
src/error.rs
17
src/error.rs
|
@ -91,20 +91,19 @@ impl fmt::Display for CompileError {
|
||||||
CompileErrorType::InvalidYield => "'yield' outside function".to_string(),
|
CompileErrorType::InvalidYield => "'yield' outside function".to_string(),
|
||||||
};
|
};
|
||||||
|
|
||||||
if self.statement.is_some() && self.location.column() > 0 {
|
if let Some(statement) = &self.statement {
|
||||||
|
if self.location.column() > 0 {
|
||||||
|
if let Some(line) = statement.lines().nth(self.location.row() - 1) {
|
||||||
// visualize the error, when location and statement are provided
|
// visualize the error, when location and statement are provided
|
||||||
write!(
|
return write!(f, "\n{}\n{}", line, self.location.visualize(&error_desc));
|
||||||
f,
|
}
|
||||||
"\n{}\n{}",
|
}
|
||||||
self.statement.clone().unwrap(),
|
}
|
||||||
self.location.visualize(&error_desc)
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
// print line number
|
// print line number
|
||||||
write!(f, "{} at {}", error_desc, self.location)
|
write!(f, "{} at {}", error_desc, self.location)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
impl Error for CompileError {
|
impl Error for CompileError {
|
||||||
fn source(&self) -> Option<&(dyn Error + 'static)> {
|
fn source(&self) -> Option<&(dyn Error + 'static)> {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue