Put Error in its own module

This commit is contained in:
Sasha Koshka 2022-08-18 00:51:19 -04:00
parent abc6e44fb2
commit ca5f8202bb

View File

@ -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 {