Skip to content

Commit

Permalink
Fix line decrement when eof does not follow a newline
Browse files Browse the repository at this point in the history
  • Loading branch information
xoltia committed Nov 24, 2024
1 parent a624bd5 commit ccf6ccc
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
4 changes: 2 additions & 2 deletions error_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,9 +252,9 @@ func TestParseError(t *testing.T) {
`
| toml: error: unexpected EOF; expected '"'
|
| At line 0, column 14:
| At line 1, column 14:
|
| 0 | string = "test
| 1 | string = "test
| ^
`,
},
Expand Down
4 changes: 3 additions & 1 deletion lex.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,9 @@ func (lx *lexer) errorPos(start, length int, err error) stateFn {
func (lx *lexer) errorf(format string, values ...any) stateFn {
if lx.atEOF {
pos := lx.getPos()
pos.Line--
if lx.pos >= 1 && lx.input[lx.pos-1] == '\n' {
pos.Line--
}
pos.Len = 1
pos.Start = lx.pos - 1
lx.items <- item{typ: itemError, pos: pos, err: fmt.Errorf(format, values...)}
Expand Down

0 comments on commit ccf6ccc

Please sign in to comment.