Use used_names not in pgen2, but only in our parser.

This commit is contained in:
Dave Halter
2014-10-22 15:50:02 +02:00
parent e2a07752fd
commit e9f4c60e49
3 changed files with 7 additions and 7 deletions

View File

@@ -56,16 +56,22 @@ class Parser(object):
# When this is True, the refactor*() methods will call write_file() for
# files processed even if they were not changed during refactoring. If
# and only if the refactor method's write parameter was True.
self.used_names = {}
logger = logging.getLogger("RefactoringTool")
d = Driver(pytree.python_grammar, convert=self.convert, logger=logger)
self.module = d.parse_string(source).get_parent_until()
self.module.used_names = self.used_names
self.module.set_global_names(self.global_names)
def convert(self, grammar, raw_node):
new_node = pytree.convert(grammar, raw_node)
if isinstance(new_node, pr.GlobalStmt):
self.global_names += new_node.names()
elif isinstance(new_node, pr.Name):
# Keep a listing of all used names
arr = self.used_names.setdefault(new_node.value, [])
arr.append(new_node)
return new_node
def __init__old__(self, source, module_path=None, no_docstr=False,

View File

@@ -97,7 +97,6 @@ class Parser(object):
stackentry = (self.grammar.dfas[start], 0, newnode)
self.stack = [stackentry]
self.rootnode = None
self.used_names = set() # Aliased to self.rootnode.used_names in pop()
def addtoken(self, type, value, context):
"""Add a token; return True iff this is the end of the program."""
@@ -149,8 +148,6 @@ class Parser(object):
def classify(self, type, value, context):
"""Turn a token into a label. (Internal)"""
if type == token.NAME:
# Keep a listing of all used names
self.used_names.add(value)
# Check for reserved words
ilabel = self.grammar.keywords.get(value)
if ilabel is not None:
@@ -186,7 +183,6 @@ class Parser(object):
node[-1].append(newnode)
else:
self.rootnode = newnode
self.rootnode.used_names = self.used_names
def error_recovery(self, type, value, context):
"""

View File

@@ -582,7 +582,7 @@ class SubModule(Scope, Module):
Depending on the underlying parser this may be a full module or just a part
of a module.
"""
__slots__ = ('path', 'global_names', 'used_names', 'temp_used_names',
__slots__ = ('path', 'global_names', 'used_names',
'line_offset', 'use_as_parent')
def __init__(self, children):
@@ -596,8 +596,6 @@ class SubModule(Scope, Module):
"""
super(SubModule, self).__init__(children)
self.path = None # Set later.
self.used_names = {}
self.temp_used_names = []
# this may be changed depending on fast_parser
self.line_offset = 0