summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThibaut Horel <thibaut.horel@gmail.com>2016-02-21 22:48:36 -0500
committerThibaut Horel <thibaut.horel@gmail.com>2016-02-21 22:48:36 -0500
commit965edb3dc0b3f6780c6763219832ac6855098b82 (patch)
treee4986a32c4cdd0ddf428a57a6e65932a0f5eac3c
parent99e5114a8b22ce692fb6cbf26b0b11908dde69e8 (diff)
downloadbibtex-965edb3dc0b3f6780c6763219832ac6855098b82.tar.gz
The panic/defer logic was not quite right
-rw-r--r--parser.go26
1 files changed, 15 insertions, 11 deletions
diff --git a/parser.go b/parser.go
index 70903fa..25830c8 100644
--- a/parser.go
+++ b/parser.go
@@ -359,10 +359,12 @@ func (p *Parser) readEntry(entry *Entry) {
}
}
-func (p *Parser) readDeclaration() {
+func (p *Parser) readDeclaration() (err error) {
+ defer errorHandler(&err, p)
+
typ := p.readIdentifier()
if typ == "" {
- panic(p.NewError("Expected entry type"))
+ err = p.NewError("Expected entry type")
}
typ = strings.ToLower(typ)
switch typ {
@@ -376,20 +378,16 @@ func (p *Parser) readDeclaration() {
entry.line = p.lineno
p.readEntry(entry)
}
+ return
}
-func errorHandler(errp *error, strict bool, p *Parser) {
+func errorHandler(errp *error, p *Parser) {
if e := recover(); e != nil {
switch e.(type) {
case ParseError:
- if strict {
- *errp = e.(ParseError)
- } else {
- log.Println(e.(ParseError).Error())
- }
+ *errp = e.(ParseError)
case error:
if e == io.EOF {
- p.Warning("Reached end of file while parsing.")
*errp = e.(error)
} else {
panic(e)
@@ -401,7 +399,6 @@ func errorHandler(errp *error, strict bool, p *Parser) {
}
func (p *Parser) Parse(strict bool) (err error) {
- defer errorHandler(&err, strict, p)
var ch rune
for {
@@ -409,7 +406,14 @@ func (p *Parser) Parse(strict bool) (err error) {
switch ch {
case '@':
p.eatSpace()
- p.readDeclaration()
+ err = p.readDeclaration()
+ if err != nil {
+ if strict {
+ return
+ } else {
+ log.Print(err.Error())
+ }
+ }
case eof:
return
}