diff options
| author | Thibaut Horel <thibaut.horel@gmail.com> | 2016-02-21 22:48:36 -0500 |
|---|---|---|
| committer | Thibaut Horel <thibaut.horel@gmail.com> | 2016-02-21 22:48:36 -0500 |
| commit | 965edb3dc0b3f6780c6763219832ac6855098b82 (patch) | |
| tree | e4986a32c4cdd0ddf428a57a6e65932a0f5eac3c /parser.go | |
| parent | 99e5114a8b22ce692fb6cbf26b0b11908dde69e8 (diff) | |
| download | bibtex-965edb3dc0b3f6780c6763219832ac6855098b82.tar.gz | |
The panic/defer logic was not quite right
Diffstat (limited to 'parser.go')
| -rw-r--r-- | parser.go | 26 |
1 files changed, 15 insertions, 11 deletions
@@ -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 } |
