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