Parslet – A Simple PEG Parser Framework for Ruby
Parslet is a new "simple parser framework" for Ruby built by Kaspar Schiess. It follows the PEG (parsing expression grammar) style of parsing and its primary goals are to be simple, testable, and to have extensive and powerful error reporting features (something that Kaspar states Treetop sorely lacks).
If you've already used Treetop, you might wonder what the hoopla is about. The key difference is that Parslet does not generate code to represent the parsing grammars you create as Treetop does - it works directly from rules defined using standard Ruby syntax (Treetop has its own Ruby-esque grammar language). Parslet's error messages are also significantly nicer than Treetop's when you inevitably run into trouble with your grammar as they're generated by Parslet itself and don't spring from Treetop's internally generated code.
So if you need to build a parser (or think you might), check out Parslet - it has a great homepage with some useful documentation. Installation is simple (gem install parslet
) and Kaspar has put together a "getting started" tutorial that walks through building a basic grammar for a teeny-tiny programming language. It concludes with a complete example of a programming language interpreter in a mere 49 lines.
Pingback: Tweets that mention Parslet – A Simple PEG Parser Framework for Ruby -- Topsy.com
January 13, 2011 at 2:42 am
So I was going to come here and say "oh dear god not another one", but then I saw "error reporting" and got interested. It's not just Kaspar stating that Treetop sorely lacks error reporting; I'd go so far (having used Treetop in production) to say that its lack of decent error reporting makes it unsuitable for real-world use. Any parser generator that takes errors seriously is worthy of real consideration.
January 17, 2011 at 2:08 am
I wonder what its speed is like. Besides error reporting, that was the main thing I ran into with Treetop.
January 17, 2011 at 2:39 am
"Once you start naming things, you’ll notice that what you don’t name, disappears. Parslet assumes that what you don’t name is unimportant."
Finally!
Transformations--also brilliant.
Glad Parslet came along.
January 17, 2011 at 10:09 pm
There's also one called Citrus.
April 7, 2011 at 4:07 am
Awesome! Long live Parslet