Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can the Scala parser framework parse a sequence supplied in "push" mode?

Tags:

parsing

scala

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.

like image 220
Michael Kay Avatar asked Nov 04 '22 15:11

Michael Kay


1 Answers

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.

like image 170
Michael Kay Avatar answered Nov 12 '22 23:11

Michael Kay