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

View File

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

View File

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

View File

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

View File

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

View File

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