Ensure FailureHandler is consulted only if there are no more alternatives.

This commit is contained in:
Fedor Isakov 2018-11-09 17:08:00 +01:00
parent c8a56558ae
commit 72e7fdfbfc
1 changed files with 16 additions and 10 deletions

View File

@ -126,7 +126,10 @@ class Controller(
trace.discard(occ)
}
for (body in match.rule().bodyAlternation()) {
val altIt = match.rule().bodyAlternation().iterator()
while (altIt.hasNext()) {
val body = altIt.next()
if (state is FAILED) {
trace.retry(match)
state = state.reset()
@ -146,17 +149,20 @@ class Controller(
}
if (state is FAILED) {
if (failureHandler != null) {
val updatedFailure = failureHandler.handleFailure(state.failure, match.rule())
if (updatedFailure == null) {
state = state.reset()
break
if (!altIt.hasNext()) {
// last alternative
if (failureHandler != null) {
val updatedFailure = failureHandler.handleFailure(state.failure, match.rule())
if (updatedFailure == null) {
state = state.reset()
}
}
}
trace.failure(state.failure)
frameStack.reset(savedFrame)
if (state is FAILED) {
trace.failure(state.failure)
frameStack.reset(savedFrame)
}
} else {
break
}