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
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 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
 | 
			
		||||
func (location Location) Describe () (description string) {
 | 
			
		||||
	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
 | 
			
		||||
		for err.Width() > 1 {
 | 
			
		||||
		for index < err.Column() + err.Width() - 1 {
 | 
			
		||||
			if line[index] == '\t' {
 | 
			
		||||
				formattedMessage += "--------"
 | 
			
		||||
			} else {
 | 
			
		||||
 | 
			
		||||
@ -242,6 +242,6 @@ func TestTokenizeErr (test *testing.T) {
 | 
			
		||||
		"../tests/lexer/error/unknownEscape.arf",
 | 
			
		||||
		infoerr.ErrorKindError,
 | 
			
		||||
		"unknown escape character g",
 | 
			
		||||
		1, 2, 1,
 | 
			
		||||
		1, 1, 7,
 | 
			
		||||
		test)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -9,9 +9,9 @@ func (lexer *LexingOperation) tokenizeString (isRuneLiteral bool) (err error) {
 | 
			
		||||
	if err != nil { return }
 | 
			
		||||
 | 
			
		||||
	token := lexer.newToken()
 | 
			
		||||
 | 
			
		||||
	got := ""
 | 
			
		||||
 | 
			
		||||
	beginning := lexer.file.Location(1)
 | 
			
		||||
	for {
 | 
			
		||||
		// TODO: add hexadecimal escape codes
 | 
			
		||||
		if lexer.char == '\\' {
 | 
			
		||||
@ -40,10 +40,11 @@ func (lexer *LexingOperation) tokenizeString (isRuneLiteral bool) (err error) {
 | 
			
		||||
	err = lexer.nextRune()
 | 
			
		||||
	if err != nil { return }
 | 
			
		||||
 | 
			
		||||
	beginning.SetWidth(len(got))
 | 
			
		||||
	if isRuneLiteral {
 | 
			
		||||
		if len(got) > 1 {
 | 
			
		||||
			err = infoerr.NewError (
 | 
			
		||||
				lexer.file.Location(1),
 | 
			
		||||
				beginning,
 | 
			
		||||
				"excess data in rune literal",
 | 
			
		||||
				infoerr.ErrorKindError)
 | 
			
		||||
			return
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user