summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xmonkey/monkey.py25
1 files changed, 15 insertions, 10 deletions
diff --git a/monkey/monkey.py b/monkey/monkey.py
index 3f58ee8..8f57235 100755
--- a/monkey/monkey.py
+++ b/monkey/monkey.py
@@ -267,14 +267,22 @@ def fix_hints(code, path):
messages = []
for step_type, idx, a, b in path:
if step_type == 'add_rule':
+ type = 'insert'
msg = 'Add another rule.'
- start = program[idx].pos
- end = start
+ start = program[idx].pos-1
+ end = start+2
elif step_type == 'add_part':
- msg = 'Add another goal.'
+ type = 'insert'
+ msg = 'Add another goal to this rule.'
+ start = program[idx].pos-1
+ end = start+2
+ elif step_type == 'remove_rule':
+ type = 'remove'
+ msg = 'Remove this rule.'
start = program[idx].pos
- end = start
+ end = program[idx + len(a) - 1].pos
elif step_type == 'remove_part':
+ type = 'remove'
msg = 'Remove this goal.'
start = program[idx].pos
end = idx + len(a) - 1
@@ -282,7 +290,8 @@ def fix_hints(code, path):
end -= 1
end = program[end].pos + len(program[end].val)
elif step_type == 'change_part':
- msg = 'Check this goal.'
+ 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]:
first += 1
@@ -291,11 +300,7 @@ def fix_hints(code, path):
last -= 1
start = program[idx+first].pos
end = program[idx+last].pos + len(program[idx+last].val)
- elif step_type == 'remove_rule':
- msg = 'Remove this rule.'
- start = program[idx].pos
- end = program[idx + len(a) - 1].pos
- messages.append(((start, end), msg))
+ messages.append(({'type': type, 'start': start, 'end': end}, msg))
program[idx:idx+len(a)] = [t.clone(pos=program[idx].pos) for t in b]