diff --git a/examples_test.go b/examples_test.go index 1e13399..ca64a1f 100644 --- a/examples_test.go +++ b/examples_test.go @@ -18,15 +18,44 @@ func ExampleItemType() { } func ExampleError() { - error := parsekit.Error{ + err := &parsekit.Error{ Message: "it broke down", Line: 10, - Column: 42} + Column: 42, + } - fmt.Println(error.Error()) - fmt.Println(error.ErrorFull()) + fmt.Println(err.Error()) + fmt.Printf("%s\n", err) + fmt.Println(err.ErrorFull()) // Output: // it broke down + // it broke down + // it broke down after line 10, column 42 +} + +func ExampleError_Error() { + err := &parsekit.Error{ + Message: "it broke down", + Line: 10, + Column: 42, + } + + fmt.Println(err.Error()) + fmt.Printf("%s\n", err) + // Output: + // it broke down + // it broke down +} + +func ExampleError_ErrorFull() { + err := &parsekit.Error{ + Message: "it broke down", + Line: 10, + Column: 42, + } + + fmt.Println(err.ErrorFull()) + // Output: // it broke down after line 10, column 42 } diff --git a/statehandler_emit.go b/statehandler_emit.go index e598bec..d34e0d5 100644 --- a/statehandler_emit.go +++ b/statehandler_emit.go @@ -74,8 +74,7 @@ func (err *Error) Error() string { // ErrorFull returns the current error message, including information about // the position in the input where the error occurred. func (err *Error) ErrorFull() string { - message := err.Error() - return fmt.Sprintf("%s after line %d, column %d", message, err.Line, err.Column) + return fmt.Sprintf("%s after line %d, column %d", err, err.Line, err.Column) } // EmitError emits a Parser error item to the client.