Can I use the Scala parser framework to parse a stream of events supplied to the parser in push mode (i.e. a sequence of write() calls)? Or does it have to "pull" its input using iterators? I'm looking at using the parser primarily to validate that the sequence of write() calls is a well-formed legitimate sequence, but it might also inject additional tokens into the stream.
I know I can push a sequence of tokens to a component that expects to pull the sequence by using threads, but that's a messy solution.
OK, the answer appears to be that the Scala parser needs to "own the control loop": it can't be driven in push mode. This is because as a recursive descent parsing engine, it needs the program stack to maintain state. It could potentially operate 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 lookahead and implement any necessary buffering.
For the purpose intended, finding a tool that generates a simple state machine seems a better way forward.
Thanks for the comments that led to this conclusion.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With