diff --git a/file/error.go b/error/error.go similarity index 80% rename from file/error.go rename to error/error.go index 7d9b578..1eac4c6 100644 --- a/file/error.go +++ b/error/error.go @@ -1,7 +1,8 @@ -package file +package error import "os" import "fmt" +import "git.tebibyte.media/sashakoshka/arf/file" type ErrorKind int @@ -11,14 +12,14 @@ const ( ) type Error struct { - Location + file.Location message string kind ErrorKind } // NewError creates a new error at the specified location. func NewError ( - location Location, + location file.Location, message string, kind ErrorKind, ) ( @@ -41,24 +42,23 @@ func (err Error) Error () (formattedMessage string) { } // print information about the location of the mistake - if err.width > 0 { + if err.Width() > 0 { formattedMessage += fmt.Sprint ( - " \033[34m", err.Location.row + 1, - ":", err.Location.column + 1) + " \033[34m", err.Row() + 1, + ":", err.Column() + 1) } formattedMessage += " \033[90min\033[0m " + - err.Location.file.path + "\n" + err.File().Path() + "\n" - if err.width > 0 { + if err.Width() > 0 { // print erroneous line - line := err.Location.file.lines[err.Location.row] - formattedMessage += - err.Location.file.lines[err.Location.row] + "\n" + line := err.File().GetLine(err.Row()) + formattedMessage += line + "\n" // position error marker var index int - for index = 0; index < err.Location.column; index ++ { + for index = 0; index < err.Column(); index ++ { if line[index] == '\t' { formattedMessage += "\t" } else { @@ -67,7 +67,7 @@ func (err Error) Error () (formattedMessage string) { } // print an arrow with a tail spanning the width of the mistake - for err.width > 1 { + for err.Width() > 1 { if line[index] == '\t' { formattedMessage += "--------" } else {