fix scanner level error reporting in Plex/Errors.py
[cython.git] / Cython / Plex / Errors.py
1 #=======================================================================
2 #
3 #   Python Lexical Analyser
4 #
5 #   Exception classes
6 #
7 #=======================================================================
8
9 class PlexError(Exception):
10   message = ""
11
12 class PlexTypeError(PlexError, TypeError):
13   pass
14
15 class PlexValueError(PlexError, ValueError):
16   pass
17
18 class InvalidRegex(PlexError):
19   pass
20
21 class InvalidToken(PlexError):
22
23   def __init__(self, token_number, message):
24     PlexError.__init__(self, "Token number %d: %s" % (token_number, message))
25
26 class InvalidScanner(PlexError):
27   pass
28
29 class AmbiguousAction(PlexError):
30   message = "Two tokens with different actions can match the same string"
31
32   def __init__(self):
33     pass
34
35 class 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