From 7717384414926eaa5821f04a08ee0d198f7b786f Mon Sep 17 00:00:00 2001 From: Mel Date: Mon, 8 Aug 2022 23:46:09 +0000 Subject: Produce (slightly) better parser errors --- pkg/lang/parser/errors.go | 60 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 pkg/lang/parser/errors.go (limited to 'pkg/lang/parser/errors.go') diff --git a/pkg/lang/parser/errors.go b/pkg/lang/parser/errors.go new file mode 100644 index 0000000..a020e01 --- /dev/null +++ b/pkg/lang/parser/errors.go @@ -0,0 +1,60 @@ +package parser + +import ( + "fmt" + "jinx/pkg/lang/scanner/token" + "jinx/pkg/libs/source" +) + +type ErrFunctionNoThisAllowed struct { + At source.Loc +} + +func (e ErrFunctionNoThisAllowed) Error() string { + return fmt.Sprintf("non-method function cannot have 'this' as parameter at %v", e.At) +} + +type ErrFunctionLiteralNoThisAllowed struct { + At source.Loc +} + +func (e ErrFunctionLiteralNoThisAllowed) Error() string { + return fmt.Sprintf("function literal cannot have 'this' as parameter at %v", e.At) +} + +type ErrExpectedToken struct { + At source.Loc + Wanted token.TokenKind + Got token.Token +} + +func (e ErrExpectedToken) Error() string { + return fmt.Sprintf("unexpected token %v, wanted %v at %v", e.Got, e.Wanted, e.At) +} + +type ErrExpectedStatementEnd struct { + At source.Loc + Got token.Token +} + +func (e ErrExpectedStatementEnd) Error() string { + return fmt.Sprintf("expected statement end, got %v at %v", e.Got, e.At) +} + +type ErrExpectedUnitExpressionStart struct { + At source.Loc + Got token.Token +} + +func (e ErrExpectedUnitExpressionStart) Error() string { + return fmt.Sprintf("unexpected token %v, wanted unit expression start at %v", e.Got, e.At) +} + +type ErrExpectedValueLiteral struct { + At source.Loc + Got token.Token +} + +func (e ErrExpectedValueLiteral) Error() string { + return fmt.Sprintf("unexpected token %v, wanted value literal %v", e.Got, e.At) +} -- cgit 1.4.1