summaryrefslogtreecommitdiff
path: root/monkey
diff options
context:
space:
mode:
Diffstat (limited to 'monkey')
-rwxr-xr-xmonkey/monkey.py13
1 files changed, 4 insertions, 9 deletions
diff --git a/monkey/monkey.py b/monkey/monkey.py
index f5b69a9..79584e0 100755
--- a/monkey/monkey.py
+++ b/monkey/monkey.py
@@ -29,7 +29,8 @@ def fix(name, code, edits, aux_code='', timeout=30, debug=False):
for start, end in rules:
rule_lines = lines[start:end]
- rule_tokens = [t for line in rule_lines for t in line]
+ rule_vars = [t.val for line in rule_lines for t in line
+ if t.type == 'VARIABLE' and t.val != '_']
# Prepend a new rule (fact) before this rule (only if no line in
# the current rule has been modified yet).
@@ -60,10 +61,7 @@ def fix(name, code, edits, aux_code='', timeout=30, debug=False):
for (before, after), cost in changes.items():
if line_normal == before:
seen = True
- mapping = map_vars(before, after, line, rule_tokens)
- after_real = tuple([t if t.type != 'VARIABLE'
- else Token('VARIABLE', mapping[t.val])
- for t in after])
+ after_real = tuple(map_vars(before, after, line, rule_vars))
new_lines = lines[:line_idx] + (after_real,) + lines[line_idx+1:]
new_step = ('change_line', line_idx, (tuple(line), after_real))
@@ -88,10 +86,7 @@ def fix(name, code, edits, aux_code='', timeout=30, debug=False):
# Don't try to insert a head into the body.
if after[-1].type == 'FROM':
continue
- mapping = map_vars([], after, [], rule_tokens)
- after_real = tuple([t if t.type != 'VARIABLE'
- else Token('VARIABLE', mapping[t.val])
- for t in after])
+ after_real = tuple(map_vars([], after, [], rule_vars))
idx = line_idx+1
new_lines = lines[:idx] + (after_real,) + lines[idx:]