From 7659eb16548f73c981a73b2434efb2746bb09bd9 Mon Sep 17 00:00:00 2001 From: Sei Lisa Date: Sat, 28 Jan 2017 03:03:06 +0100 Subject: [PATCH] Use frozenset for keywords; allow Pop. Rather than using tuples for set belonging, use a frozen set. That eliminates the need to separate them by lengths. Also, 'Pop' is not a reserved word. It's perfectly valid as a possible substitution identifier, so allow it. If used, it will go to the used words anyway and thus will be skipped by the sequential name generator. --- lslopt/lslrenamer.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lslopt/lslrenamer.py b/lslopt/lslrenamer.py index 5371a03..4757c41 100644 --- a/lslopt/lslrenamer.py +++ b/lslopt/lslrenamer.py @@ -29,8 +29,10 @@ class renamer(object): CharSet1 = '_ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz' CharSet2 = '0123456789_ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz' # TODO: Derive these from builtins.txt somehow. - KwByLen = ((), (), ('do', 'if', 'PI'), ('for', 'key', 'EOF', 'Pop'), - ('jump', 'else', 'list', 'TRUE', 'LOOP', 'case')) + Kws = (frozenset({'do', 'if', 'PI', + 'for', 'key', 'EOF', + 'jump', 'else', 'list', 'TRUE', 'LOOP', 'case' + })) def GetNextShortest(self): """Generate the next shortest possible identifier""" while True: @@ -48,7 +50,7 @@ class renamer(object): else: self.WordRestOfChars.append(0) - if ret not in self.KwByLen[len(ret)] and ret not in self.UsedNames: + if ret not in self.Kws and ret not in self.UsedNames: return ret def ShrinkNames(self):