about summary refs log tree commit diff
path: root/pkg/lang/parser/stmts.go
diff options
context:
space:
mode:
authorMel <einebeere@gmail.com>2022-08-08 23:46:09 +0000
committerMel <einebeere@gmail.com>2022-08-08 23:46:09 +0000
commit7717384414926eaa5821f04a08ee0d198f7b786f (patch)
tree0b667518eba4c8d023d39a70fecf153a795a7f9c /pkg/lang/parser/stmts.go
parente0161c493867e788ad9db208247f3275e2d057dc (diff)
downloadjinx-7717384414926eaa5821f04a08ee0d198f7b786f.tar.zst
jinx-7717384414926eaa5821f04a08ee0d198f7b786f.zip
Produce (slightly) better parser errors
Diffstat (limited to 'pkg/lang/parser/stmts.go')
-rw-r--r--pkg/lang/parser/stmts.go8
1 files changed, 5 insertions, 3 deletions
diff --git a/pkg/lang/parser/stmts.go b/pkg/lang/parser/stmts.go
index c20f7a0..fe5c65b 100644
--- a/pkg/lang/parser/stmts.go
+++ b/pkg/lang/parser/stmts.go
@@ -1,7 +1,6 @@
 package parser
 
 import (
-	"fmt"
 	"jinx/pkg/lang/ast"
 	"jinx/pkg/lang/scanner/token"
 )
@@ -154,7 +153,7 @@ func (p *Parser) parseFnDeclStmt() (ast.Stmt, error) {
 	}
 
 	if hasThis {
-		return ast.Stmt{}, fmt.Errorf("function cannot have 'this' as a parameter")
+		return ast.Stmt{}, ErrFunctionNoThisAllowed{At: fnTok.At}
 	}
 
 	block, err := p.parseBlock()
@@ -640,7 +639,10 @@ func (p *Parser) parseEmptyStmt() (ast.Stmt, error) {
 func (p *Parser) parseStmtEnd() error {
 	tok := p.peek()
 	if !tok.CanEndStmt() {
-		return fmt.Errorf("wanted statement end, received: '%v'", tok.Kind)
+		return ErrExpectedStatementEnd{
+			At:  tok.At,
+			Got: tok,
+		}
 	}
 	p.next()
 	return nil