From ee098e3ec03b58053ae491c68e6e74111f105612 Mon Sep 17 00:00:00 2001 From: Timotej Lazar Date: Wed, 25 Mar 2015 14:59:37 +0100 Subject: Tweak message handling code --- monkey/monkey.py | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) (limited to 'monkey') diff --git a/monkey/monkey.py b/monkey/monkey.py index 8f57235..fd11868 100755 --- a/monkey/monkey.py +++ b/monkey/monkey.py @@ -260,29 +260,28 @@ def fix(name, code, edits, aux_code='', timeout=30, debug=False): return '', [], total_time, n_tested -# Return a list of pairs (range, message) describing edits in [path]. +# Return tuples (type, start, end, message) describing edits in [path]. def fix_hints(code, path): program = list(annotate(code)) - messages = [] for step_type, idx, a, b in path: if step_type == 'add_rule': - type = 'insert' + fix_type = 'insert' msg = 'Add another rule.' start = program[idx].pos-1 end = start+2 elif step_type == 'add_part': - type = 'insert' + fix_type = 'insert' msg = 'Add another goal to this rule.' start = program[idx].pos-1 end = start+2 elif step_type == 'remove_rule': - type = 'remove' + fix_type = 'remove' msg = 'Remove this rule.' start = program[idx].pos end = program[idx + len(a) - 1].pos elif step_type == 'remove_part': - type = 'remove' + fix_type = 'remove' msg = 'Remove this goal.' start = program[idx].pos end = idx + len(a) - 1 @@ -290,7 +289,7 @@ def fix_hints(code, path): end -= 1 end = program[end].pos + len(program[end].val) elif step_type == 'change_part': - type = 'change' + fix_type = 'change' msg = 'Check this part.' first = 0 while idx+first < len(program)-1 and first < len(a) and first < len(b) and a[first] == b[first]: @@ -300,8 +299,6 @@ def fix_hints(code, path): last -= 1 start = program[idx+first].pos end = program[idx+last].pos + len(program[idx+last].val) - messages.append(({'type': type, 'start': start, 'end': end}, msg)) program[idx:idx+len(a)] = [t.clone(pos=program[idx].pos) for t in b] - - return messages + yield fix_type, start, end, msg -- cgit v1.2.1