Files
core/lexer/error.go
T
amery 7ca5f7be25 lexer: ErrUnacceptableRune
Signed-off-by: Alejandro Mery <amery@jpi.io>
2023-08-29 16:28:47 +00:00

52 lines
813 B
Go

package lexer
import (
"errors"
"fmt"
"strings"
)
var (
_ error = (*Error)(nil)
)
var (
// ErrUnacceptableRune indicates the read rune
ErrUnacceptableRune = errors.New("rune not acceptable in context")
)
// Error represents a generic parsing error
type Error struct {
Filename string
Line int
Column int
Content string
Err error
}
func (err Error) Error() string {
var s []string
switch {
case err.Line > 0 || err.Column > 0:
s = append(s, fmt.Sprintf("%s:%v:%v", err.Filename, err.Line, err.Column))
case err.Filename != "":
s = append(s, err.Filename)
}
if err.Err != nil {
s = append(s, err.Err.Error())
}
if err.Content != "" {
s = append(s, fmt.Sprintf("%q", err.Content))
}
return strings.Join(s, ": ")
}
func (err Error) Unwrap() error {
return err.Err
}