From b74e7223ce76f4c00e677fd18fb6815412c6911a Mon Sep 17 00:00:00 2001 From: David Beazley Date: Tue, 16 Jan 2018 08:30:09 -0600 Subject: [PATCH] Added extra validation check in Lexer construction --- CHANGES | 6 ++++++ sly/lex.py | 2 ++ 2 files changed, 8 insertions(+) diff --git a/CHANGES b/CHANGES index 40af0eb..988aa6b 100644 --- a/CHANGES +++ b/CHANGES @@ -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 ----------- diff --git a/sly/lex.py b/sly/lex.py index 9ac6575..82b5a24 100644 --- a/sly/lex.py +++ b/sly/lex.py @@ -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