Start from the back, finding the last lexeme/member of a non-backtracking rule that fails. In repeating constructions (*a
, +a
, repeat(n, m)[a]
and a % b
) the last member will always fail (all their branches) before it knows to end.
An example from my answer yesterday, the end of a successful *task_item
parse:
...
<attributes>[[[[[[V, a, r, 1], [=, =], [T, e, s, t]], [&, &], [[[V, a, r, 2], [<, =], 10], [&, &], [[V, a, r, 3]
, [=, =], [D, o, n, e]]]], [[[W, o, r, d], 32, [O, b, j, e, c, t, i, v, e]], [[[[V, a, r, 3], [=, =], [A]], [|, |],
[[[V, a, r, 4], [=, =], [B]], [&, &], [[V, a, r, 5], [>], 0]]], [[[V, a, r, N, a, m, e], [V, a, l, u, e, 1]], [[V, a
, r, 2], 10]], [[[[V, a, r, 3], [=, =], [C]], [[[V, a, r, N, a, m, e], [S, o, m, e, V, a, l, u, e]]], [empty]]]]], [
[[[V, a, r, N, a, m, e], [V, a, l, u, e, 2]]]]]]]</attributes>
</task_item>
<task_item>
<try></try>
<classdef_>
<try></try>
<fail/>
</classdef_>
<statement_>
<try></try>
<assign_>
<try></try>
<assign_>
<try></try>
<fail/>
</assign_>
<fail/>
</assign_>
<verify_>
<try></try>
<fail/>
</verify_>
<conditional_>
<try></try>
<fail/>
</conditional_>
<fail/>
</statement_>
<fail/>
</task_item>
<success></success>
<attributes>[[[[[[V, a, r, 1], [=, =], [T, e, s, t]], [&, &], [[[V, a, r, 2], [<, =], 10], [&, &], [[V, a, r, 3],
[=, =], [D, o, n, e]]]], [[[W, o, r, d], 32, [O, b, j, e, c, t, i, v, e]], [[[[V, a, r, 3], [=, =], [A]], [|, |], [[
[V, a, r, 4], [=, =], [B]], [&, &], [[V, a, r, 5], [>], 0]]], [[[V, a, r, N, a, m, e], [V, a, l, u, e, 1]], [[V, a,
r, 2], 10]], [[[[V, a, r, 3], [=, =], [C]], [[[V, a, r, N, a, m, e], [S, o, m, e, V, a, l, u, e]]], [empty]]]]], [[[
[V, a, r, N, a, m, e], [V, a, l, u, e, 2]]]]]]]</attributes>
</task_>
In an unsuccessful parse, you will usually have to find for the last specific rule that fails where you expected it to pass.