Skip to content

Commit c028818

Browse files
committed
Fix SyntaxError visualize order: message first location later
1 parent 8d62b76 commit c028818

File tree

2 files changed

+4
-8
lines changed

2 files changed

+4
-8
lines changed

compiler/src/error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ impl fmt::Display for CompileError {
125125
if self.location.column() > 0 {
126126
if let Some(line) = statement.lines().nth(self.location.row() - 1) {
127127
// visualize the error, when location and statement are provided
128-
return write!(f, "\n{}\n{}", line, self.location.visualize(&error_desc));
128+
return write!(f, "{}", self.location.visualize(line, &error_desc));
129129
}
130130
}
131131
}

parser/src/location.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,9 @@ impl fmt::Display for Location {
1616
}
1717

1818
impl Location {
19-
pub fn visualize(&self, desc: &str) -> String {
20-
format!(
21-
"{}↑\n{}{}",
22-
" ".repeat(self.column - 1),
23-
" ".repeat(self.column - 1),
24-
desc
25-
)
19+
pub fn visualize(&self, line: &str, desc: &str) -> String {
20+
// desc.to_owned()
21+
format!("{}\n{}\n{}↑", desc, line, " ".repeat(self.column - 1))
2622
}
2723
}
2824

0 commit comments

Comments
 (0)