InfoQ has a great (i.e., entertaining, interesting, and pragmatic) interview with two Domain Specific Language (DSL) developers, here
. I highly recommend watching it. In that interview, Ruby is used to define the DSL, but Groovy can also be used for this purpose, for which all the related resources can be found here
. But, I wanted to really
understand what all of this is about, and even though the sessions on this subject at the Grails eXchange were helpful, it wasn't until I followed the steps in this blog
that I began to really "get it". At the end of it, you can calculate distances and measurements and compare them to each other, using a brand new notation defined in Groovy DSL. So, as one can see in the editor below, it is possible to use the DSL to type '1000.m.km' and, because
of your DSL, Groovy is able to understand that what you are actually saying
is: "Convert 1000 meters to kilometers", such that it correctly resolves it, as shown in the Output window below:
Note that, in Groovy, "1000.m.km" doesn't mean anything at all. In fact, the Groovy file would have thrown a runtime error, if I had typed that string without specifying the DSL that I wanted to use to interpret my string.
All this is pretty cool to see in action. Basically, what you're doing is extending Groovy. Now it makes real sense to me and now I can begin reading the theoretical stories and the slides from various presentations. Having a complete, working sample is the beginning of knowledge.