I was recently asked by Manning to review their upcoming book on DSLs, called DSLs In Action. Obviously, i agreed to the review because not only does that mean i get a free book, it's also on a topic that i happen to be very interested in right now because we're writing a DSL at work. Let's go over the contents of the book, shall we?
The first chapter is an introduction to the importance of everyone involved with a project speaking the same language and DSLs in general, including a good listing of the benefits and drawbacks of implementing a DSL. If you've already done any kind of DSL implementation, there's nothing new for you in this chapter, though it is a very good introduction to people who are new at it and want to learn more about it.
Chapter 2 wastes no time in showing you how you can start building your own DSL. The first example is done in Java, but is quickly superseded by a Groovy implementation which is far more expressive than its Java counterpart. The author then covers some DSL implementation patterns for both internal and external DSLs, and then discusses some of the factors you need to keep in mind when deciding to go with an internal DSL (running within the context of a host language) or an external DSL (stands on its own without having to run inside a host language). Chapter 3 covers some of the topics that you'll definitely need to be aware of when implementing a DSL, such as patterns for integration of your DSL with the actual application that you're building (both in the context of internal as well as external DSLs), dealing with errors and exceptions, and finally, some performance related factors worth keeping in mind.
The next 3 chapters cover internal DSLs exclusively. Chapter 4 discusses a set of implementation patterns for internal DSLs, such as leaning on meta-programming techniques, taking advantage of typed-abstractions, runtime generation, and macros for compile time code generation. Obviously, the applicability of these techniques depends on which language you're using, and are nicely illustrated with examples in Ruby, Groovy and Scala. Chapter 5 covers the implementation of a DSL in each of the following languages: Ruby, Groovy and Clojure. Again, the examples do a nice job of highlighting each language's strong points and what kind of results you can get from them. To conclude the chapter, a nice list of common pitfalls that you need to avoid is discussed. The next chapter covers the implementation of a DSL in Scala. It's very heavy on the Scala usage (obviously) and was IMO, one of the two most difficult chapters of the book. If you're familiar with Scala, it'll probably be much easier to get through though but a lot of interesting stuff is covered, even if you don't quite understand all of the syntax. And the resulting examples of the implemented DSLs are the most expressive ones in the entire book, at least as far as internal DSLs are concerned.
After this extensive look at implementing internal DSLs, the next 2 chapters shift their focus to the implementation of external DSLs. I was very curious to see how this would turn out because up until now, i'd never bothered to look into the creation of external DSLs because i thought it would be far too complex. After reading those 2 chaptes, i'm glad to say that while it's no trivial task, it's not exactly rocket science either. You'll see examples of how to define the grammar of your language using EBNF notation, and how you can leverage the power of libraries like ANTLR to make the whole task of parsing your DSL much easier. You'll also see some interesting examples using XText which is more of a DSL workbench. Chapter 8 takes you back to the Scala world to show you can use Parser Combinators in Scala to write an external DSL. This chapter is once again very complex, but very interesting at the same time. The book then concludes with a short final chapter where the author looks forward to the future of DSL based development.
All in all, there is a lot of very interesting and useful information in this book. You'll learn a lot of the things that you'll need to know about to make an informed decision as to which approaches you should following when implementing a DSL. You'll also learn a lot of cool tricks to make your DSLs as expressive as they can be. I can't think of a better book to get you started with DSL development. The only thing that prevents me from labeling this as a Highly Recommended book is that it doesn't cover some of the topics you need to learn about to make sure your success with a DSL is sustainable in the long term. Things like testing your DSL, backwards compatibility, versioning, etc are not covered and it is somewhat missed.