diff options
| -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 } |
