Location now stores width instead of Error

This commit is contained in:
Sasha Koshka 2022-08-12 13:43:09 -05:00
parent 050c956787
commit 7914f0df45
6 changed files with 11 additions and 12 deletions

View File

@ -12,7 +12,6 @@ const (
type Error struct {
Location
width int
message string
kind ErrorKind
}
@ -20,7 +19,6 @@ type Error struct {
// NewError creates a new error at the specified location.
func NewError (
location Location,
width int,
message string,
kind ErrorKind,
) (
@ -28,7 +26,6 @@ func NewError (
) {
return &Error {
Location: location,
width: width,
message: message,
kind: kind,
}

View File

@ -108,5 +108,6 @@ func (file *File) Location () (location Location) {
file: file,
row: file.currentLine,
column: file.currentColumn,
width: 1,
}
}

View File

@ -6,4 +6,5 @@ type Location struct {
file *File
row int
column int
width int
}

View File

@ -35,7 +35,7 @@ func (lexer *LexingOperation) tokenize () (err error) {
if err != nil || shebangCheck[index] != lexer.char {
err = file.NewError (
lexer.file.Location(), 1,
lexer.file.Location(),
"not an arf file",
file.ErrorKindError)
return
@ -119,7 +119,7 @@ func (lexer *LexingOperation) tokenizeSymbolBeginning () (err error) {
err = lexer.nextRune()
file.NewError (
lexer.file.Location(), 1,
lexer.file.Location(),
"tab not used as indent",
file.ErrorKindWarn).Print()
return
@ -272,7 +272,7 @@ func (lexer *LexingOperation) tokenizeSymbolBeginning () (err error) {
err = lexer.nextRune()
default:
err = file.NewError (
lexer.file.Location(), 1,
lexer.file.Location(),
"unexpected symbol character " +
string(lexer.char),
file.ErrorKindError)
@ -334,7 +334,7 @@ func (lexer *LexingOperation) nextRune () (err error) {
lexer.char, _, err = lexer.file.ReadRune()
if err != nil && err != io.EOF {
return file.NewError (
lexer.file.Location(), 1,
lexer.file.Location(),
err.Error(), file.ErrorKindError)
}
return

View File

@ -23,7 +23,7 @@ func (lexer *LexingOperation) tokenizeNumberBeginning (negative bool) (err error
number, fragment, isFloat, err = lexer.tokenizeNumber(8)
} else {
return file.NewError (
lexer.file.Location(), 1,
lexer.file.Location(),
"unexpected character in number literal",
file.ErrorKindError)
}

View File

@ -43,7 +43,7 @@ func (lexer *LexingOperation) tokenizeString (isRuneLiteral bool) (err error) {
if isRuneLiteral {
if len(got) > 1 {
err = file.NewError (
lexer.file.Location(), len(got) - 1,
lexer.file.Location(),
"excess data in rune literal",
file.ErrorKindError)
return
@ -99,7 +99,7 @@ func (lexer *LexingOperation) getEscapeSequence () (result rune, err error) {
if len(number) < 3 {
err = file.NewError (
lexer.file.Location(), 1,
lexer.file.Location(),
"octal escape sequence too short",
file.ErrorKindError)
return
@ -133,7 +133,7 @@ func (lexer *LexingOperation) getEscapeSequence () (result rune, err error) {
if len(number) < want {
err = file.NewError (
lexer.file.Location(), 1,
lexer.file.Location(),
"hex escape sequence too short ",
file.ErrorKindError)
return
@ -143,7 +143,7 @@ func (lexer *LexingOperation) getEscapeSequence () (result rune, err error) {
result = rune(parsedNumber)
} else {
err = file.NewError (
lexer.file.Location(), 1,
lexer.file.Location(),
"unknown escape character " +
string(lexer.char), file.ErrorKindError)
return