diff options
| author | Mel <einebeere@gmail.com> | 2022-08-08 23:46:09 +0000 |
|---|---|---|
| committer | Mel <einebeere@gmail.com> | 2022-08-08 23:46:09 +0000 |
| commit | 7717384414926eaa5821f04a08ee0d198f7b786f (patch) | |
| tree | 0b667518eba4c8d023d39a70fecf153a795a7f9c /pkg/lang/parser/exprs.go | |
| parent | e0161c493867e788ad9db208247f3275e2d057dc (diff) | |
| download | jinx-7717384414926eaa5821f04a08ee0d198f7b786f.tar.zst jinx-7717384414926eaa5821f04a08ee0d198f7b786f.zip | |
Produce (slightly) better parser errors
Diffstat (limited to 'pkg/lang/parser/exprs.go')
| -rw-r--r-- | pkg/lang/parser/exprs.go | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/pkg/lang/parser/exprs.go b/pkg/lang/parser/exprs.go index 48d1a8c..1603838 100644 --- a/pkg/lang/parser/exprs.go +++ b/pkg/lang/parser/exprs.go @@ -1,7 +1,6 @@ package parser import ( - "fmt" "jinx/pkg/lang/ast" "jinx/pkg/lang/scanner/token" ) @@ -207,7 +206,8 @@ func (p *Parser) parseUnitExpr() (ast.Expr, error) { case token.KwTrue, token.KwFalse, token.KwNull, token.KwThis: return p.parseValueLitExpr() default: - panic(fmt.Errorf("unexpected token '%v', wanted unit expression start", p.peek().Kind)) + tok := p.peek() + return ast.Expr{}, ErrExpectedUnitExpressionStart{tok.At, tok} } } @@ -250,7 +250,7 @@ func (p *Parser) parseFnLitExpr() (ast.Expr, error) { } if hasThis { - return ast.Expr{}, fmt.Errorf("function literal cannot have 'this' parameter") + return ast.Expr{}, ErrFunctionLiteralNoThisAllowed{fnTok.At} } // TODO: Also parse just an expression @@ -406,6 +406,6 @@ func (p *Parser) parseValueLitExpr() (ast.Expr, error) { Value: ast.ExprThis{}, }, nil default: - panic(fmt.Errorf("unexpected token '%v', wanted value literal", tok)) + return ast.Expr{}, ErrExpectedValueLiteral{At: tok.At, Got: tok} } } |
