From 720f4aa6426e1463757b3192e13b9f705a354a65 Mon Sep 17 00:00:00 2001 From: Timotej Lazar Date: Sat, 28 Feb 2015 19:10:46 +0100 Subject: Simplify calls to prolog.util.map_vars --- monkey/monkey.py | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) (limited to 'monkey') 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:] -- cgit v1.2.1