Number of blocks opened and not yet closed.
True once a terminal finish chunk arrived or the stream was aborted.
Record that the consumer abandoned the stream.
Abort is a legitimate termination — it is how cancellation reaches this layer — so it settles the grammar rather than failing it. What it must not do is leave the grammar accepting: a chunk arriving after the consumer stopped listening is output nobody will ever sign.
Assert the stream reached a terminal finish chunk.
Called when a consumer claims the stream completed normally. A provider that just stopped sending — a dropped connection read as an ending — must not be recorded as a clean completion.
Validate one chunk against the grammar and advance the state.
Throws on the first violation. Nothing is folded, nothing is signed, and the caller's stream is dead: a stream that broke the contract once cannot be trusted to have told the truth about what came before.
The stream grammar as a state machine over one provider stream.
Not reusable across streams and not resettable: a grammar instance is one-to-one with a stream, so leftover state cannot leak between attempts.