ginger/gg/v2/location.go

37 lines
677 B
Go

package gg
import "fmt"
// Location indicates a position in a stream of bytes identified by column
// within newline-separated rows.
type Location struct {
Row, Col int
}
func (l Location) errf(str string, args ...any) LocatedError {
return LocatedError{l, fmt.Errorf(str, args...)}
}
func (l Location) locate() Location { return l }
// LocatedError is an error related to a specific point within a decode gg
// stream.
type LocatedError struct {
Location
Err error
}
func (e LocatedError) Error() string {
return fmt.Sprintf("%d:%d: %v", e.Row, e.Col, e.Err)
}
type locatableRune struct {
Location
r rune
}
type locatableString struct {
Location
str string
}