diff options
author | Timotej Lazar <timotej.lazar@araneo.org> | 2015-02-28 19:10:46 +0100 |
---|---|---|
committer | Aleš Smodiš <aless@guru.si> | 2015-08-11 14:26:02 +0200 |
commit | 720f4aa6426e1463757b3192e13b9f705a354a65 (patch) | |
tree | fb3d747e78639c67f2fba551e91675da98042dbe /monkey | |
parent | 901643b3736333a92baefaf029aae28c237c5aab (diff) |
Simplify calls to prolog.util.map_vars
Diffstat (limited to 'monkey')
-rwxr-xr-x | monkey/monkey.py | 13 |
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:] |