Merge pull request #3 from pydanny/master
Added index of error to LexError
This commit is contained in:
commit
c0694aa922
@ -41,11 +41,13 @@ class LexError(Exception):
|
|||||||
'''
|
'''
|
||||||
Exception raised if an invalid character is encountered and no default
|
Exception raised if an invalid character is encountered and no default
|
||||||
error handler function is defined. The .text attribute of the exception
|
error handler function is defined. The .text attribute of the exception
|
||||||
contains all remaining untokenized text.
|
contains all remaining untokenized text. The .error_index is the index
|
||||||
|
location of the error.
|
||||||
'''
|
'''
|
||||||
def __init__(self, message, text):
|
def __init__(self, message, text, error_index):
|
||||||
self.args = (message,)
|
self.args = (message,)
|
||||||
self.text = text
|
self.text = text
|
||||||
|
self.error_index = error_index
|
||||||
|
|
||||||
class PatternError(Exception):
|
class PatternError(Exception):
|
||||||
'''
|
'''
|
||||||
@ -252,4 +254,4 @@ class Lexer(metaclass=LexerMeta):
|
|||||||
|
|
||||||
# Default implementations of the error handler. May be changed in subclasses
|
# Default implementations of the error handler. May be changed in subclasses
|
||||||
def error(self, value):
|
def error(self, value):
|
||||||
raise LexError(f'Illegal character {value[0]!r} at index {self.index}', value)
|
raise LexError(f'Illegal character {value[0]!r} at index {self.index}', value, self.index)
|
||||||
|
Loading…
Reference in New Issue
Block a user