When blogging about DSLs, I’m mostly blogging about internal domain-specific languages, because jOOQ is a good example for internal DSLs. But external domain-specific languages are an interesting topic as well. As an external DSL does not depend on any host language (e.g. Java), it can be much richer in syntax and expressivity. On the other hand, you need tools to parse, compile and maybe even interpret / run them.
Here’s a very interesting blog post showing how to create an external DSL with Xtext, Eclipse’s DSL tool chain. It creates a simple DSL to describe video game control flows and shows how Eclipse Xtext immediately provides an editor with all sorts of IDE features for that custom DSL:
who is frequently commenting on the lambda-dev
and other Java 8 mailing lists, has recently published an idea he has been having for a while: ElSql, a new external SQL DSL for Java.
An example SQL statement is given on the blog posts or on GitHub
WHERE id = :id
date > :date
active = :active
ORDER BY title, author
title, author, content
As can be seen, this is almost mere string-based SQL, enhanced with some “hooks” for later use in Java. While Stephen’s idea here is to keep it simple (much simpler than jOOQ
) it shows some useful applications of allowing to write external DSLs which resemble SQL even more than jOOQ
DSL authoring support is becoming a more and more interesting topic in various platforms. Eclipse is developing Xtext
, Scala is experimenting with even more powerful Macros
. While Xtext doesn’t allow to mix the DSL grammar with Java, Scala’s Macros do precisely that. They allow for simple compile-time checked Scala syntax extension, if you have a powerful enough CPU to compile such source code. Where this could go for jOOQ was discussed on this blog before
For more details, read about ElSql on Stephen’s or the OpenGamma blog: