Fix SyntaxError visualize order: message first location later

This commit is contained in:
Jeong YunWon committed 2020-05-30 01:07:38 +00:00
1 parent e4be376336
commit 7bce7baf4a
2 files changed
+4 -8

No files matched your search

+1 -1
View File
@@ -125,7 +125,7 @@ impl fmt::Display for CompileError {
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
return write!(f, "\n{}\n{}", line, self.location.visualize(&error_desc));
return write!(f, "{}", self.location.visualize(line, &error_desc));
}
}
}
+3 -7
View File
@@ -16,13 +16,9 @@ impl fmt::Display for Location {
}
impl Location {
pub fn visualize(&self, desc: &str) -> String {
format!(
"{}↑\n{}{}",
" ".repeat(self.column - 1),
" ".repeat(self.column - 1),
desc
)
pub fn visualize(&self, line: &str, desc: &str) -> String {
// desc.to_owned()
format!("{}\n{}\n{}↑", desc, line, " ".repeat(self.column - 1))
}
}