State-based parser.

The old parser required the ability to look forward in the stream, but that
isn’t possible with a reader, so the new parser uses a state machine.