From 061b85376e76c3b28afa488369dff76241cc5c7c Mon Sep 17 00:00:00 2001 From: Thibaut Horel Date: Sun, 21 Feb 2016 21:30:12 -0500 Subject: Warn about existing key as soon as it starts --- parser.go | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'parser.go') diff --git a/parser.go b/parser.go index d9106c0..fae51d6 100644 --- a/parser.go +++ b/parser.go @@ -1,4 +1,4 @@ -package main +package bibtex import ( "bufio" @@ -342,6 +342,13 @@ func (p *Parser) readEntry(entry *Entry) error { p.eatSpace() key := p.readToken("," + string(close)) entry.key = key + + if _, in := p.entries[strings.ToLower(key)]; in { + p.Warning(fmt.Sprintf("Entry %q already defined, ignoring", key)) + } else { + p.entries[strings.ToLower(key)] = entry + } + for { p.eatSpace() if ch := p.read(); ch == close { @@ -388,12 +395,6 @@ func (p *Parser) readDeclaration() error { entry := NewEntry(typ) entry.line = p.lineno err = p.readEntry(entry) - if _, in := p.entries[strings.ToLower(entry.key)]; in { - p.Warning(fmt.Sprintf("Entry %q already defined, ignoring", - entry.key)) - } else { - p.entries[strings.ToLower(entry.key)] = entry - } } return err } -- cgit v1.2.3-70-g09d2