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

@@ -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