Treetop – Powerful But Easy Ruby Parser Library
Treetop is a very well put together Ruby library for building Ruby-powered parsers. Treetop makes it possible to rapidly put together parsers for your own mini languages (a basic "arithmetic" parser is the main demonstration used on the Treetop site) and relies on parsing expression grammars to make it a pretty easy process.
Back in 2006 I posted about my own Ruby recursive descent parser on Ruby Inside, but Treetop goes a lot further in making it developer friendly and more powerful overall, even going as far as making blending grammars together as easy as mixing Ruby modules! Another key difference between a raw recursive descent parser and Treetop is that Treetop actually generates Ruby code that works on your particular grammar, somewhat like yacc or Ragel.
This is a really exciting project if you're into parsing or need to build a parser, so check it out. The official site has lots of useful documentation (although not many particularly deep examples, but they are bound to come in time). If you end up using Treetop to produce something, make sure to let me know!
January 25, 2008 at 4:45 pm
Have not gone through the whole documentation, but a quick question is it something which can help us write code reviews and if it is so then is there any project working on code review?
January 25, 2008 at 5:05 pm
I probably should add something saying that this isn't something that parses Ruby, but a "parser" library written in Ruby. So, no, unless you wrote a whole spec for Ruby in Treetop's syntax, I don't think code review would be a use case for this. That would be more a job for ParseTree and ruby2ruby.
January 25, 2008 at 6:28 pm
I saw this presented at RubyConf 2007 and have to say I was thoroughly impressed. Very slick and well worth looking at.
January 25, 2008 at 6:29 pm
Sorry -- I meant to include the link to the rubyconf presentation video:
http://rubyconf2007.confreaks.com/d1t1p5_treetop.html
January 25, 2008 at 7:32 pm
I recorded and interview with Mr. Sobo last week in San Francisco. I hope to post it to the Rails Podcast within the next few weeks.
January 25, 2008 at 8:00 pm
I've been using this fairly heavily since RubyConf to write a full grammar for IDL (the data processing language, not the interface description one.) There are a few rough edges, but I've been able to develop a fully functional grammar in a remarkably short span of time. Treetop is seriously useful.
January 28, 2008 at 2:16 am
Just testing something.. sorry!