Added extra validation check in Lexer construction

This commit is contained in:
David Beazley 2018-01-16 08:30:09 -06:00
parent e9346daff0
commit b74e7223ce
2 changed files with 8 additions and 0 deletions

View File

@ -1,3 +1,9 @@
Version 0.3
-----------
1/16/2018 Usability improvement on Lexer class. Regular expression rules
specified as strings that don't match any name in tokens are
now reported as errors.
Version 0.2
-----------

View File

@ -141,6 +141,8 @@ class Lexer(metaclass=LexerMeta):
for key, value in definitions:
if (key in cls.tokens) or key.startswith('ignore_') or hasattr(value, 'pattern'):
rules.append((key, value))
elif isinstance(value, str) and not key.startswith('_') and key not in {'ignore'}:
raise LexerBuildError(f'{key} does not match a name in tokens')
return rules
@classmethod