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/errors.go | |
| parent | e0161c493867e788ad9db208247f3275e2d057dc (diff) | |
| download | jinx-7717384414926eaa5821f04a08ee0d198f7b786f.tar.zst jinx-7717384414926eaa5821f04a08ee0d198f7b786f.zip | |
Produce (slightly) better parser errors
Diffstat (limited to 'pkg/lang/parser/errors.go')
| -rw-r--r-- | pkg/lang/parser/errors.go | 60 |
1 files changed, 60 insertions, 0 deletions
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) +} |
