From: James Gray Date: 2008-09-24T22:32:50+09:00 Subject: Re: ANTLR Target for Ruby On Sep 24, 2008, at 7:23 AM, Eric Mahurin wrote: > I'm sounds like I > won't be able to convince you why a DSL is better than a specific > format, > and you vice-versa. A quick summary is: although you lose the exact > syntax > that you may want, you gain in power and flexibility. Using Grammar > (directly), you could template Grammars (method/lambda could return a > Grammar based on Grammar args and other params), use plain ruby for > extra > control when specifying a Grammar tree, or simply embed Grammar > objects in a > ruby program (like Regexp objects can be - although they parse the > grammar > from a string). When I wrote GhostWheel, I was convinced the DSL was better too. Then I tried using it and changed my mind. :) The DSL adds a lot of Ruby noise that makes it harder to think about and understand the language being parsed. It keeps you from focusing on the right things. For example, compare this JSON parser using GhostWheel's DSL: http://ghostwheel.rubyforge.org/svn/trunk/test/example/tc_json_ruby.rb and this using a grammar: http://ghostwheel.rubyforge.org/svn/trunk/test/example/tc_json_ghost_wheel.rb I'm not arguing my grammar is perfect either. I think it could get even more readable. But have a look at how clear rules like value_space, value_content, value, and value_with_array_sep play out. I also think most of the advantages you list can be gained with non- DSL grammars. I mean, we can always dynamically build up a String in Ruby too and that's the dumbest thing I could possibly think of. Anyway, the two don't have to be exclusive. As you see, GhostWheel supports both. James Edward Gray II