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.
This commit is contained in:
Sei Lisa 2017-01-28 03:03:06 +01:00
parent 9b09c29eea
commit 7659eb1654

View file

@ -29,8 +29,10 @@ class renamer(object):
CharSet1 = '_ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz' CharSet1 = '_ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
CharSet2 = '0123456789_ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz' CharSet2 = '0123456789_ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
# TODO: Derive these from builtins.txt somehow. # TODO: Derive these from builtins.txt somehow.
KwByLen = ((), (), ('do', 'if', 'PI'), ('for', 'key', 'EOF', 'Pop'), Kws = (frozenset({'do', 'if', 'PI',
('jump', 'else', 'list', 'TRUE', 'LOOP', 'case')) 'for', 'key', 'EOF',
'jump', 'else', 'list', 'TRUE', 'LOOP', 'case'
}))
def GetNextShortest(self): def GetNextShortest(self):
"""Generate the next shortest possible identifier""" """Generate the next shortest possible identifier"""
while True: while True:
@ -48,7 +50,7 @@ class renamer(object):
else: else:
self.WordRestOfChars.append(0) 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 return ret
def ShrinkNames(self): def ShrinkNames(self):