From 7fc51c278f5d48256afccdb82b9d7c184cdf5e5c Mon Sep 17 00:00:00 2001 From: Sasha Koshka Date: Mon, 15 Aug 2022 14:30:54 -0400 Subject: [PATCH] Fixed issue with Error.Error not positioning marker correctly --- file/error.go | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/file/error.go b/file/error.go index 7cb437b..3f40a72 100644 --- a/file/error.go +++ b/file/error.go @@ -52,20 +52,30 @@ func (err Error) Error () (formattedMessage string) { if err.width > 0 { // print erroneous line + line := err.Location.file.lines[err.Location.row] formattedMessage += err.Location.file.lines[err.Location.row] + "\n" + // position error marker + var index int + for index = 0; index < err.Location.column; index ++ { + if line[index] == '\t' { + formattedMessage += "\t" + } else { + formattedMessage += " " + } + } + // print an arrow with a tail spanning the width of the mistake - columnCountdown := err.Location.column - for columnCountdown > 1 { - // TODO: for tabs, print out a teb instead. - formattedMessage += " " - columnCountdown -- - } for err.width > 1 { - // TODO: for tabs, print out 8 of these instead. - formattedMessage += "-" + if line[index] == '\t' { + formattedMessage += "--------" + } else { + formattedMessage += "-" + } + index ++ } + formattedMessage += "^\n" } formattedMessage += err.message + "\n"