From: Clifford Heath Date: 2008-09-26T11:04:37+09:00 Subject: Re: ANTLR Target for Ruby James Gray wrote: > When I wrote GhostWheel, I was convinced the DSL was better too. Then > I tried using it and changed my mind. :) > For example, compare this JSON parser using GhostWheel's DSL: > http://ghostwheel.rubyforge.org/svn/trunk/test/example/tc_json_ghost_wheel.rb > 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. A trick I've been wanting to use in a DSL would make your Ghostwheel example start like this: def setup @parser = GhostWheel.build_parser {%q{ ... }} end By passing a block to build_parser, you're also passing that block's binding. Now, after build_parser calls the block to get the string it must parse, it can identify references to variables including local variables in the "setup" method, and it can get and set values for those variables, or call methods on the referenced objects. I plan to use this to access query parameters when I embed CQL queries into Ruby. No need for string interpolation, just name the variable in the CQL and the query engine can access the Ruby object that contains the value - nice! Just another reason why a parsed language doesn't have to be second-class to a DSL. Clifford Heath.