PageRenderTime 74ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/src/htsql/tr/error.py

https://bitbucket.org/pombredanne/htsql
Python | 111 lines | 89 code | 8 blank | 14 comment | 3 complexity | 8015ae77238f31d1d53efa28b32276ad MD5 | raw file
  1. #
  2. # Copyright (c) 2006-2011, Prometheus Research, LLC
  3. # See `LICENSE` for license information, `AUTHORS` for the list of authors.
  4. #
  5. """
  6. :mod:`htsql.tr.error`
  7. =====================
  8. This module declares exceptions that can be raised by the HTSQL-to-SQL
  9. translator.
  10. """
  11. from ..util import maybe
  12. from ..error import BadRequestError
  13. from ..mark import Mark
  14. class TranslateError(BadRequestError):
  15. """
  16. Represents a translation error.
  17. """
  18. def __init__(self, detail, mark, hint=None):
  19. assert isinstance(mark, Mark)
  20. assert isinstance(hint, maybe(str))
  21. super(TranslateError, self).__init__(detail)
  22. self.mark = mark
  23. self.hint = hint
  24. def __str__(self):
  25. lines = self.mark.excerpt()
  26. mark_detail = "\n".join(" "+line.encode('utf-8') for line in lines)
  27. return "%s: %s:\n%s%s" % (self.kind, self.detail, mark_detail,
  28. "\n(%s)" % self.hint
  29. if self.hint is not None else "")
  30. class ScanError(TranslateError):
  31. """
  32. Represents a scanner error.
  33. This exception is raised when the scanner cannot tokenize a query.
  34. """
  35. kind = "scan error"
  36. class ParseError(TranslateError):
  37. """
  38. Represents a parser error.
  39. This exception is raised by the parser when it encounters an unexpected
  40. token.
  41. """
  42. kind = "parse error"
  43. class BindError(TranslateError):
  44. """
  45. Represents a binder error.
  46. Raised when the binder is unable to bind a syntax node.
  47. """
  48. kind = "bind error"
  49. class EncodeError(TranslateError):
  50. """
  51. Represents an encoder error.
  52. Raised when the encoder is unable to encode or relate a binding node.
  53. """
  54. kind = "encode error"
  55. class CompileError(TranslateError):
  56. """
  57. Represents a compiler error.
  58. Raised when the compiler is unable to generate a term node.
  59. """
  60. kind = "compile error"
  61. class AssembleError(TranslateError):
  62. """
  63. Represents an assembler error.
  64. Raised when the assembler is unable to generate a frame or a phrase node.
  65. """
  66. kind = "assemble error"
  67. class SerializeError(TranslateError):
  68. """
  69. Represents a serializer error.
  70. Raised when the serializer is unable to translate a clause node to SQL.
  71. """
  72. kind = "serialize error"