goparsify/errors.go

27 lines
835 B
Go
Raw Normal View History

2017-08-13 08:56:12 +02:00
package goparsify
import "fmt"
// Error represents a parse error. These will often be set, the parser will back up a little and
// find another viable path. In general when combining errors the longest error should be returned.
type Error struct {
pos int
expected string
}
// Pos is the offset into the document the error was found
func (e *Error) Pos() int { return e.pos }
// Error satisfies the golang error interface
func (e *Error) Error() string { return fmt.Sprintf("offset %d: expected %s", e.pos, e.expected) }
// UnparsedInputError is returned by Run when not all of the input was consumed. There may still be a valid result
type UnparsedInputError struct {
2019-06-18 13:14:22 +02:00
Remaining string
2017-08-13 08:56:12 +02:00
}
// Error satisfies the golang error interface
func (e UnparsedInputError) Error() string {
2019-06-18 13:14:22 +02:00
return "left unparsed: " + e.Remaining
2017-08-13 08:56:12 +02:00
}