diff --git a/lexer.go b/lexer.go index 63ae242..a3057c4 100644 --- a/lexer.go +++ b/lexer.go @@ -44,6 +44,7 @@ const ( func (t TokenType) String() string { types := []string{ "EOF", + "Undefined", "TagStart", "TagEnd", "TagKey", diff --git a/pgn.go b/pgn.go index e9fa8ea..5947e9d 100644 --- a/pgn.go +++ b/pgn.go @@ -519,7 +519,7 @@ func (p *Parser) parseVariation() error { // the last move before the variation start variationParent = parentMove.parent // Reset position to where the variation starts - if variationParent.parent != nil { + if variationParent.parent != nil && variationParent.parent.position != nil { p.game.pos = variationParent.parent.position.copy() if newPos := p.game.pos.Update(variationParent); newPos != nil { p.game.pos = newPos diff --git a/polyglot.go b/polyglot.go index af56927..ae6f2ed 100644 --- a/polyglot.go +++ b/polyglot.go @@ -194,12 +194,12 @@ func LoadFromSource(source BookSource) (*PolyglotBook, error) { buf := make([]byte, 16) for { - _, err := source.Read(buf) - if err == io.EOF { + _, readErr := source.Read(buf) + if readErr == io.EOF { break } - if err != nil { - return nil, err + if readErr != nil { + return nil, readErr } entry := PolyglotEntry{ diff --git a/polyglot_test.go b/polyglot_test.go index e5be5e4..01a867c 100644 --- a/polyglot_test.go +++ b/polyglot_test.go @@ -3,6 +3,7 @@ package chess import ( "bytes" "encoding/binary" + "errors" "io" "os" "path/filepath" @@ -60,7 +61,7 @@ func TestBytesBookSource(t *testing.T) { // Test EOF source.index = 32 n, err = source.Read(buf) - if err != io.EOF { + if !errors.Is(err, io.EOF) { t.Errorf("Read() error = %v, want EOF", err) } }