Quantcast

Using Parboiled as a push parser

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Using Parboiled as a push parser

Geoff
Hey guys,

edit: view this post with markdown rendering here: https://gist.github.com/Groostav/4ee39620d4559d4c7046c734d8e2f6ea

Has anyone had any experience using Parboiled as a push parser?

Right Now I'm using ANTLR to parse an event sequence to generate a list of undo/redo-able actions. It works fairly well, with the one notable exception that, because ANTLR cannot be used as a push parser (at least formally), I have to re-parse the entire event sequence every time a new event comes in. Since antlr is fast this isn't a performance issue so much as a least-suprise issue: in order to create a facade of "new events coming in", we have to perform a logical diff on the resulting parse tree from `parse(eventSeq1)` and `parse(eventSeq1 + newEvent)`. That diffing logic involves a number of complex caches, and is very bug prone.

I was hoping to replace this parser with parboiled, but it would be hugely convenient to me if I could use parboiled as a push parser.

What I mean by this is as follows: I would write a parboiled grammar and a parse tree visitor. With an empty set of tokens, I would then write `parseTree.accept(myVisitor)`. When a new event comes in, I would execute `parboiled.tokens += newEvent`. Parboiled would then use any shift/reduce rules it had, _in combination with any local stack events_ (events not consumed by a previous parse), to _append_ any new parse nodes to the existing parse tree, and resume `myVisitor` (call any necessary visit methods).

Does this sound feasible?

Thanks for any help!
Loading...