Refactoring step.

This commit is contained in:
Eric S. Raymond 2007-04-11 08:28:37 +00:00
parent 6ad8ea6916
commit c210423fdf

View File

@ -85,6 +85,15 @@ class CrossRef:
if trial in self.fileref: if trial in self.fileref:
return trial return trial
return None return None
def mark_matching_resources(self, pattern, fn, n):
"Mark all definitions matching a specified pattern with a reference."
pattern = re.compile(pattern + "$")
key = None
for trial in self.fileref:
if pattern.match(trial):
key = trial
self.fileref[key].append(fn, n)
return key
def __init__(self, filelist): def __init__(self, filelist):
# First, collect macro definitions from the specified filelist." # First, collect macro definitions from the specified filelist."
self.xref = {} self.xref = {}
@ -157,13 +166,10 @@ class CrossRef:
# it as a reference to everything the substitutions # it as a reference to everything the substitutions
# could potentially match. # could potentially match.
elif '{' in name: elif '{' in name:
pattern = re.sub(r"\{[^}]*\}", '.*', name) pattern = "^" + re.sub(r"\{[^}]*\}", '.*', name)
pattern = re.compile("^" + pattern + "$") key = self.mark_matching_resources(pattern, fn,n+1)
key = None if key:
for trial in self.fileref: self.fileref[key].append(fn, n+1)
if pattern.match(trial):
key = trial
self.fileref[key].append(fn, n+1)
else: else:
key = self.imagesearch(name) key = self.imagesearch(name)
if key: if key: