Fixed issue with Error.Error not positioning marker correctly
This commit is contained in:
parent
3a3c588023
commit
7fc51c278f
@ -52,20 +52,30 @@ func (err Error) Error () (formattedMessage string) {
|
|||||||
|
|
||||||
if err.width > 0 {
|
if err.width > 0 {
|
||||||
// print erroneous line
|
// print erroneous line
|
||||||
|
line := err.Location.file.lines[err.Location.row]
|
||||||
formattedMessage +=
|
formattedMessage +=
|
||||||
err.Location.file.lines[err.Location.row] + "\n"
|
err.Location.file.lines[err.Location.row] + "\n"
|
||||||
|
|
||||||
// print an arrow with a tail spanning the width of the mistake
|
// position error marker
|
||||||
columnCountdown := err.Location.column
|
var index int
|
||||||
for columnCountdown > 1 {
|
for index = 0; index < err.Location.column; index ++ {
|
||||||
// TODO: for tabs, print out a teb instead.
|
if line[index] == '\t' {
|
||||||
|
formattedMessage += "\t"
|
||||||
|
} else {
|
||||||
formattedMessage += " "
|
formattedMessage += " "
|
||||||
columnCountdown --
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// print an arrow with a tail spanning the width of the mistake
|
||||||
for err.width > 1 {
|
for err.width > 1 {
|
||||||
// TODO: for tabs, print out 8 of these instead.
|
if line[index] == '\t' {
|
||||||
|
formattedMessage += "--------"
|
||||||
|
} else {
|
||||||
formattedMessage += "-"
|
formattedMessage += "-"
|
||||||
}
|
}
|
||||||
|
index ++
|
||||||
|
}
|
||||||
|
|
||||||
formattedMessage += "^\n"
|
formattedMessage += "^\n"
|
||||||
}
|
}
|
||||||
formattedMessage += err.message + "\n"
|
formattedMessage += err.message + "\n"
|
||||||
|
Reference in New Issue
Block a user