PageRenderTime 854ms CodeModel.GetById 13ms RepoModel.GetById 1ms app.codeStats 0ms

/src/htsql/core/tr/error.py

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