From 6bd7d6f6cca5703a449191a6fa475e74ff345c0a Mon Sep 17 00:00:00 2001 From: Jun Nishimura Date: Sat, 28 Sep 2024 22:55:50 +0900 Subject: [PATCH] handle with linter error (#16) --- parser/parser.go | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/parser/parser.go b/parser/parser.go index 95dca4f..b92984c 100644 --- a/parser/parser.go +++ b/parser/parser.go @@ -155,23 +155,30 @@ func (p *Parser) parseExpression() (ast.Expression, error) { return p.parseAtom() } -func (p *Parser) parseObject() (ast.Expression, error) { - defer p.expectCurToken(token.RBRACE) - +func (p *Parser) parseObject() (obj ast.Expression, err error) { if err := p.expectCurToken(token.LBRACE); err != nil { return nil, err } switch p.peekToken.Type { case token.COMMAND: - return p.parseCommand() + obj, err = p.parseCommand() case token.IF: - return p.parseIfExpression() + obj, err = p.parseIfExpression() case token.SET: - return p.parseSetExpression() + obj, err = p.parseSetExpression() default: - return nil, fmt.Errorf("unexpected token type %s", p.curToken.Type) + err = fmt.Errorf("unexpected token type %s", p.curToken.Type) + } + if err != nil { + return nil, err } + + if err := p.expectCurToken(token.RBRACE); err != nil { + return nil, err + } + + return obj, nil } func (p *Parser) parseCommand() (*ast.CommandObject, error) {