Reputation: 163322
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.
Upvotes: 5
Views: 256
Reputation: 163322
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.
Upvotes: 2