From accf5288696945ed80e5842d06bdda9ad5c25d44 Mon Sep 17 00:00:00 2001 From: Sasha Koshka Date: Fri, 12 Aug 2022 13:51:38 -0500 Subject: [PATCH] Locations and tokens are now capable of creating errors on their own --- file/error.go | 4 ++-- file/location.go | 5 +++++ lexer/token.go | 5 +++++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/file/error.go b/file/error.go index cfdb853..7cb437b 100644 --- a/file/error.go +++ b/file/error.go @@ -22,9 +22,9 @@ func NewError ( message string, kind ErrorKind, ) ( - err *Error, + err Error, ) { - return &Error { + return Error { Location: location, message: message, kind: kind, diff --git a/file/location.go b/file/location.go index e20abb5..1be5ff6 100644 --- a/file/location.go +++ b/file/location.go @@ -8,3 +8,8 @@ type Location struct { column int width int } + +// NewError creates a new error at this location. +func (location Location) NewError (message string, kind ErrorKind) (err Error) { + return NewError(location, message, kind) +} diff --git a/lexer/token.go b/lexer/token.go index 6247031..8e171ed 100644 --- a/lexer/token.go +++ b/lexer/token.go @@ -86,6 +86,11 @@ func (token Token) Location () (location file.Location) { return token.location } +// NewError creates a new error at this token's location. +func (token Token) NewError (message string, kind file.ErrorKind) (err file.Error) { + return token.location.NewError(message, kind) +} + // Describe generates a textual description of the token to be used in debug // logs. func (token Token) Describe () (description string) {