Skip to content

Commit 9a05b79

Browse files
authored
Merge pull request #175 from ianlewis/170-bug-customlexer-returns-eof-from-err
fix: do not return EOF from Err
2 parents a4bb786 + 2a9212d commit 9a05b79

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

custom.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,6 @@ func (l *CustomLexer) NextToken(ctx context.Context) *Token {
212212

213213
// The state is nil and we have no tokens to return, so we are at the end
214214
// of the input.
215-
l.err = io.EOF
216-
217215
return l.newToken(TokenTypeEOF)
218216
}
219217

@@ -455,6 +453,8 @@ func (l *CustomLexer) Emit(typ TokenType) *Token {
455453
return token
456454
}
457455

456+
// newToken creates a new token starting from the current cursor position to the
457+
// current reader position.
458458
func (l *CustomLexer) newToken(typ TokenType) *Token {
459459
return &Token{
460460
Type: typ,

custom_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -948,7 +948,7 @@ func TestCustomLexer_NextToken(t *testing.T) {
948948
t.Errorf("Err (-want +got):\n%s", diff)
949949
}
950950

951-
if diff := cmp.Diff(io.EOF, customLexer.Err(), cmpopts.EquateErrors()); diff != "" {
951+
if diff := cmp.Diff(nil, customLexer.Err(), cmpopts.EquateErrors()); diff != "" {
952952
t.Errorf("Err (-want +got):\n%s", diff)
953953
}
954954
})

0 commit comments

Comments
 (0)