OK, the answer seems to be that the Scala parser should "own the control loop": it cannot be started in push mode. This is because, as a mechanism for recursive analysis of parsing, a program stack is required to maintain state. It can potentially work on a separate stack by running it as an independent thread, but, of course, one would have to think about whether the grammar requires backtracking and / or viewing and does any necessary buffering.
For the intended purpose, finding the tool that generates a simple state machine seems like the best way forward.
Thanks for the comments that led to this conclusion.
source
share