1 #=======================================================================
3 # Python Lexical Analyser
7 #=======================================================================
9 class PlexError(Exception):
12 class PlexTypeError(PlexError
, TypeError):
15 class PlexValueError(PlexError
, ValueError):
18 class InvalidRegex(PlexError
):
21 class InvalidToken(PlexError
):
23 def __init__(self
, token_number
, message
):
24 PlexError
.__init
__(self
, "Token number %d: %s" % (token_number
, message
))
26 class InvalidScanner(PlexError
):
29 class AmbiguousAction(PlexError
):
30 message
= "Two tokens with different actions can match the same string"
35 class UnrecognizedInput(PlexError
):
40 def __init__(self
, scanner
, state_name
):
41 self
.scanner
= scanner
42 self
.position
= scanner
.get_position()
43 self
.state_name
= state_name
46 return ("'%s', line %d, char %d: Token not recognised in state %s"
47 % (self
.position
+ (repr(self
.state_name
),)))