From dc08a1b4662d08e4e2ac91d7a12cac5e0de2e9bb Mon Sep 17 00:00:00 2001 From: David Beazley Date: Mon, 12 Sep 2016 14:24:03 -0500 Subject: [PATCH] Modified lex to allow rules to be attached to token strings --- sly/lex.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/sly/lex.py b/sly/lex.py index a31dd80..a5dbd23 100644 --- a/sly/lex.py +++ b/sly/lex.py @@ -74,7 +74,11 @@ class LexerMetaDict(OrderedDict): ''' def __setitem__(self, key, value): if key in self and not isinstance(value, property): - raise AttributeError('Name %s redefined' % (key)) + if isinstance(self[key], str) and callable(value): + value.pattern = self[key] + else: + raise AttributeError('Name %s redefined' % (key)) + super().__setitem__(key, value) class LexerMeta(type):