go-parsekit/error.go

32 lines
802 B
Go

package parsekit
import (
"fmt"
)
// Error is used as the error type when parsing errors occur.
// The error includes some context information to allow for useful
// error messages to the user.
type Error struct {
Message string
Cursor Cursor
}
func (err *Error) Error() string {
if err == nil {
_, linepos := getCaller(1)
panic(fmt.Sprintf("parsekit.Error.Error(): method called with nil error at %s", linepos))
}
return err.Message
}
// Full returns the current error message, including information about
// the position in the input where the error occurred.
func (err *Error) Full() string {
if err == nil {
_, linepos := getCaller(1)
panic(fmt.Sprintf("parsekit.Error.Full(): method called with nil error at %s", linepos))
}
return fmt.Sprintf("%s at %s", err, err.Cursor)
}