Error widths now work properly
This commit is contained in:
parent
85996b2554
commit
a87973c141
@ -34,6 +34,11 @@ func (location Location) Width () (width int) {
|
|||||||
return location.width
|
return location.width
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetWidth sets the location's width
|
||||||
|
func (location *Location) SetWidth (width int) {
|
||||||
|
location.width = width
|
||||||
|
}
|
||||||
|
|
||||||
// Describe generates a description of the location for debug purposes
|
// Describe generates a description of the location for debug purposes
|
||||||
func (location Location) Describe () (description string) {
|
func (location Location) Describe () (description string) {
|
||||||
return fmt.Sprint (
|
return fmt.Sprint (
|
||||||
|
@ -67,7 +67,7 @@ func (err Error) Error () (formattedMessage string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// print an arrow with a tail spanning the width of the mistake
|
// print an arrow with a tail spanning the width of the mistake
|
||||||
for err.Width() > 1 {
|
for index < err.Column() + err.Width() - 1 {
|
||||||
if line[index] == '\t' {
|
if line[index] == '\t' {
|
||||||
formattedMessage += "--------"
|
formattedMessage += "--------"
|
||||||
} else {
|
} else {
|
||||||
|
@ -242,6 +242,6 @@ func TestTokenizeErr (test *testing.T) {
|
|||||||
"../tests/lexer/error/unknownEscape.arf",
|
"../tests/lexer/error/unknownEscape.arf",
|
||||||
infoerr.ErrorKindError,
|
infoerr.ErrorKindError,
|
||||||
"unknown escape character g",
|
"unknown escape character g",
|
||||||
1, 2, 1,
|
1, 1, 7,
|
||||||
test)
|
test)
|
||||||
}
|
}
|
||||||
|
@ -9,9 +9,9 @@ func (lexer *LexingOperation) tokenizeString (isRuneLiteral bool) (err error) {
|
|||||||
if err != nil { return }
|
if err != nil { return }
|
||||||
|
|
||||||
token := lexer.newToken()
|
token := lexer.newToken()
|
||||||
|
|
||||||
got := ""
|
got := ""
|
||||||
|
|
||||||
|
beginning := lexer.file.Location(1)
|
||||||
for {
|
for {
|
||||||
// TODO: add hexadecimal escape codes
|
// TODO: add hexadecimal escape codes
|
||||||
if lexer.char == '\\' {
|
if lexer.char == '\\' {
|
||||||
@ -40,10 +40,11 @@ func (lexer *LexingOperation) tokenizeString (isRuneLiteral bool) (err error) {
|
|||||||
err = lexer.nextRune()
|
err = lexer.nextRune()
|
||||||
if err != nil { return }
|
if err != nil { return }
|
||||||
|
|
||||||
|
beginning.SetWidth(len(got))
|
||||||
if isRuneLiteral {
|
if isRuneLiteral {
|
||||||
if len(got) > 1 {
|
if len(got) > 1 {
|
||||||
err = infoerr.NewError (
|
err = infoerr.NewError (
|
||||||
lexer.file.Location(1),
|
beginning,
|
||||||
"excess data in rune literal",
|
"excess data in rune literal",
|
||||||
infoerr.ErrorKindError)
|
infoerr.ErrorKindError)
|
||||||
return
|
return
|
||||||
|
Reference in New Issue
Block a user