pub fn parse<P>(
parser: &mut P,
initial: P::Token,
) -> Response<P::Action, P::TimerId>where
P: ShiftReduceParser,Expand description
Process a token through a shift-reduce parser, producing a Response.
§Loop semantics
The driver loop calls ShiftReduceParser::decide on the current token.
Depending on the result:
| Result | Actions accumulated | on_reduce called | Next iteration |
|---|---|---|---|
Shift | — | No | Return immediately |
Reduce | Yes | Yes | Return immediately |
ReduceAndContinue | Yes | Yes | Loop with remaining |
PassThrough | — | No | Return immediately |
§consumed semantics
The returned Response::consumed flag is true if any of the
following is true:
- The terminal action was
ShiftorReduce(event was handled), or - At least one
ReduceAndContinuestep accumulated actions before aPassThroughwas reached.
The second case means that even if the final PassThrough would normally
mean “not consumed,” the event is still considered consumed because the
parser did useful work in earlier iterations of the loop.
§Termination
The loop always terminates because every path through decide either
returns a terminal variant (Shift, Reduce, PassThrough) — which
causes an immediate return — or returns ReduceAndContinue with a
new token. The new token is always a value that already existed in the
caller’s token stream; the grammar must ensure no cycle exists (e.g.,
a token that always ReduceAndContinues into itself). In practice,
the remaining token is typically processed via a different match arm
that does not produce another ReduceAndContinue.