34 lines
966 B
Go
34 lines
966 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
|
|
Line int
|
|
Column int
|
|
}
|
|
|
|
func (err *Error) Error() string {
|
|
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 {
|
|
return fmt.Sprintf("%s at line %d, column %d", err, err.Line, err.Column)
|
|
}
|
|
|
|
// Error sets the error message in the parser API. This error message
|
|
// will eventually be returned by the Parser.Execute() method.
|
|
func (p *ParseAPI) Error(format string, args ...interface{}) {
|
|
// No call to p.panicWhenStoppedOrInError(), to allow a parser to
|
|
// set a different error message when needed.
|
|
message := fmt.Sprintf(format, args...)
|
|
p.err = &Error{message, p.cursorLine, p.cursorColumn}
|
|
}
|