Skip to content

Instantly share code, notes, and snippets.

@Groostav
Created August 12, 2016 20:27
Show Gist options
  • Save Groostav/4ee39620d4559d4c7046c734d8e2f6ea to your computer and use it in GitHub Desktop.
Save Groostav/4ee39620d4559d4c7046c734d8e2f6ea to your computer and use it in GitHub Desktop.
request for help using Parboiled as a push parser from the community

Hey guys,

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment