Compare commits

..

No commits in common. "d42d0c5b34e3d470073ab42c49f821e7d5d9900d" and "abc6e44fb223241e23e321e54534dd98c8f74bfd" have entirely different histories.

View File

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