Can a Scala parser parse a sequence represented in push mode?

Is it possible to use the Scala framework to parse the stream of events passed to the parser in push mode (i.e. write () call sequences)? Or should he "pull" his input with iterators? I consider using the parser primarily to verify that the write () call sequence is a correctly formed legitimate sequence, but it can also inject additional tokens into the stream.

I know that I can push the sequence of tokens towards a component that expects to output the sequence using streams, but this is a dirty decision.

+5
source share
1 answer

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.

+2
source

All Articles