Errors.py 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #=======================================================================
  2. #
  3. # Python Lexical Analyser
  4. #
  5. # Exception classes
  6. #
  7. #=======================================================================
  8. class PlexError(Exception):
  9. message = ""
  10. class PlexTypeError(PlexError, TypeError):
  11. pass
  12. class PlexValueError(PlexError, ValueError):
  13. pass
  14. class InvalidRegex(PlexError):
  15. pass
  16. class InvalidToken(PlexError):
  17. def __init__(self, token_number, message):
  18. PlexError.__init__(self, "Token number %d: %s" % (token_number, message))
  19. class InvalidScanner(PlexError):
  20. pass
  21. class AmbiguousAction(PlexError):
  22. message = "Two tokens with different actions can match the same string"
  23. def __init__(self):
  24. pass
  25. class UnrecognizedInput(PlexError):
  26. scanner = None
  27. position = None
  28. state_name = None
  29. def __init__(self, scanner, state_name):
  30. self.scanner = scanner
  31. self.position = scanner.get_position()
  32. self.state_name = state_name
  33. def __str__(self):
  34. return ("'%s', line %d, char %d: Token not recognised in state %r" % (
  35. self.position + (self.state_name,)))