errors.go 733 B

12345678910111213141516171819202122232425262728293031323334353637
  1. package expr
  2. import (
  3. `fmt`
  4. )
  5. // SyntaxError represents a syntax error in the expression.
  6. type SyntaxError struct {
  7. Pos int
  8. Reason string
  9. }
  10. func newSyntaxError(pos int, reason string) *SyntaxError {
  11. return &SyntaxError {
  12. Pos : pos,
  13. Reason : reason,
  14. }
  15. }
  16. func (self *SyntaxError) Error() string {
  17. return fmt.Sprintf("Syntax error at position %d: %s", self.Pos, self.Reason)
  18. }
  19. // RuntimeError is an error which would occure at run time.
  20. type RuntimeError struct {
  21. Reason string
  22. }
  23. func newRuntimeError(reason string) *RuntimeError {
  24. return &RuntimeError {
  25. Reason: reason,
  26. }
  27. }
  28. func (self *RuntimeError) Error() string {
  29. return "Runtime error: " + self.Reason
  30. }