summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThibaut Horel <thibaut.horel@gmail.com>2016-02-21 21:30:12 -0500
committerThibaut Horel <thibaut.horel@gmail.com>2016-02-21 21:30:12 -0500
commit061b85376e76c3b28afa488369dff76241cc5c7c (patch)
treeeffd6945c7eac205598c136afc8bdf9edb3547a0
parentc488ccf95be73c2e1ed3ed537891d8bc75e64555 (diff)
downloadbibtex-061b85376e76c3b28afa488369dff76241cc5c7c.tar.gz
Warn about existing key as soon as it starts
-rw-r--r--parser.go15
1 files changed, 8 insertions, 7 deletions
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
}