You can’t. This is one of the reasons Lezer parsers are recommended—they make it much easier to implement contextual logic (also for folding, indentation, etc). I think a language like yours should be pretty straightforward to port to Lezer.
Indeed, WaveQL is a very simple language. It is similar to Forth. Is just words separated by spaces.
At first I did write parser in Lazer. But then I encounter the fact that Lazer is not re-parsing all my source text when I edit it. I know it is nice feature, but highlighting of WaveQL depends on hierarchical vocabulary, that is traversing and types of words it finds.
Streaming parser has a state path that is updated sequentially from start for finish and help to assign right types to the tokens.
Following your advice I rewrote it again in Lezer and can’t get correct tokens.
I know I am doing something extremely wrong.
Here is full commit: Lezer version of parser · wavedrom/ql@926db10 · GitHub