Skip to content

Commit

Permalink
Remove source pointer in error if wide chars are used
Browse files Browse the repository at this point in the history
  • Loading branch information
antonmedv committed Mar 4, 2020
1 parent 13d13fd commit e498575
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
16 changes: 6 additions & 10 deletions file/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import (
"fmt"
"strings"
"unicode/utf8"

"golang.org/x/text/width"
)

type Error struct {
Expand All @@ -18,11 +16,6 @@ const (
ind = "^"
)

var (
wideDot = width.Widen.String(dot)
wideInd = width.Widen.String(ind)
)

func (e *Error) Error() string {
return e.Message
}
Expand All @@ -46,17 +39,20 @@ func (e *Error) Format(source *Source) string {
_, sz := utf8.DecodeRune(bytes)
bytes = bytes[sz:]
if sz > 1 {
indLine += wideDot
goto noind
} else {
indLine += dot
}
}
if _, sz := utf8.DecodeRune(bytes); sz > 1 {
indLine += wideInd
goto noind
} else {
indLine += ind
}
result += srcLine + indLine
srcLine += indLine

noind:
result += srcLine
}
return result
}
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,4 @@ require (
github.com/rivo/tview v0.0.0-20200219210816-cd38d7432498
github.com/sanity-io/litter v1.2.0
github.com/stretchr/testify v1.5.1
golang.org/x/text v0.3.2
)
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ github.com/stretchr/testify v0.0.0-20161117074351-18a02ba4a312/go.mod h1:a8OnRci
github.com/stretchr/testify v1.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H4=
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
golang.org/x/sys v0.0.0-20190626150813-e07cf5db2756/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200212091648-12a6c2dcc1e4 h1:sfkvUWPNGwSV+8/fNqctR5lS2AqCSqYwXdrjCxp/dXo=
golang.org/x/sys v0.0.0-20200212091648-12a6c2dcc1e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
Expand Down
4 changes: 4 additions & 0 deletions parser/lexer/lexer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,10 @@ id "hello
literal not terminated (1:10)
| id "hello
| .........^
früh ♥︎
unrecognized character: U+2665 '♥' (1:7)
| früh ♥︎
`

func TestLex_error(t *testing.T) {
Expand Down

0 comments on commit e498575

Please sign in to comment.