Which language (that runs on JVM) is best suited for creating a DSL?
Asked Answered
V

8

9

We have a requirement to create complex fixed length and variable length Strings. These strings might represent a customer profile, an order etc. Which JVM based programming language do you guys suggest?

Idea is for a end user to create the strings using this DSL. So I am looking for validation, code completion etc.

Vary answered 24/1, 2011 at 4:10 Comment(4)
How fast does it have to be? How soon do you need to make it?Papistry
@Papistry - It need not be super fastVary
what about very fast? will very fast do? or only super fast? j/k :pSystemize
Does it need to be able to do the Kessel Run in less than 12 parsecs? Cause I dunno about that...Retral
C
5

With Xtext (http://www.eclipse.org/Xtext/) you get a nice editor for free when specifying your DSL.

Catchword answered 24/1, 2011 at 14:39 Comment(5)
We extensively ue oAW for our meta models and code generation. From what I have experienced, the editors are weak. They are not ready for customer facing applications.Vary
@Pangea: that is maybe because oAW is two years no more maintained. Xtext is a rewrite, it reached 1.0 in last Eclipse release train (Galileo). The tool is perfect fit for the use case - it offers validations and auto-complete, outline, hyperlinking, quickfixes, highlighting and much more. Most of these things would never be possible to do as an internal DSL using any of languages suggested.Beard
@Gabriel thx for this update. I will look into this now. Appreciate if you can point me to the articles and examples of the DSLs created using new Xtext.Vary
@Pangea some good examples can be found on the official Xtext page here: eclipse.org/Xtext/communityBeard
Xtext is mature. And it's actively maintained and enhanced. If you need professional help I can also recommend Itemis, the company "behind" Xtext (I'm not affiliated with them at all).Catchword
B
8

Use a Lisp that runs on the JVM. Some choices you have:

  1. Clojure
  2. JScheme
  3. SISC
  4. ABCL
  5. Bigloo (Does not run on the JVM but has good Java interoperability).

There is a good free book that explains how to use Lisp to design software bottom-up, i.e how to grow Lisp into a language that is ideal to solve the problem at hand.

Languages in the Forth family are also great for defining DSLs. There are a few that runs on the JVM:

  1. Niue
  2. Misty Beach Forth
Blunge answered 24/1, 2011 at 4:59 Comment(1)
Here is a list of DSLs created with Clojure: https://mcmap.net/q/467524/-are-there-any-clojure-dslsHeavyarmed
S
6

There are two types of DSL; external and embedded.

An external DSL is completely separate from your host language i.e. you write it outside the language but is usually used to generate code in the host language. For this approach, XText with XPand are probably the best tools as a simple grammar file generates a complete Eclipse based editor for the new DSL and you can use code templates in XPand to generate actual Java code. XTend and XPand are written in Java but this is incidental as they could be written in anything so long as you end up with Java code at the end of the process. The downside with this approach, is that for any reasonably complex problem the language will become quite complex and a lot of work will be required in the grammar and even more in the code generation templates. You can't use any host language features like expression evaluation so all of this needs rebuilding in your DSL if you need it. XText will shortly include XBase which is a partial language that will include expressions to help out here.

The other approach is an embedded DSL where high-level domain features are expressed in the host language either with higher-order constructs (like HOF's and monads) typically found in functional languages or through meta-programming facilities like macros (e.g. Lisp). Java has neither of these so is a bad choice for DSL work (or most other forms of abstract programming). Spring Roo offers a meta-programming type facility for java using generation so might be an option. Failing that, Scala is probably the most Java like JVM language that is popular and has the facilities that you need.

Embedded DSL's are usually much easier than external DSL's because you have the full support of the host language so my recommendation would be to try Scala.

Sherd answered 2/2, 2011 at 10:46 Comment(1)
thanks for a detailed pros and cons, not just saying do it in my funky beloved jvm languageLayoff
C
5

Scala all the way! Scala is especially suitable for internal DSL (pls refer this).

Charlacharlady answered 24/1, 2011 at 5:22 Comment(0)
C
5

With Xtext (http://www.eclipse.org/Xtext/) you get a nice editor for free when specifying your DSL.

Catchword answered 24/1, 2011 at 14:39 Comment(5)
We extensively ue oAW for our meta models and code generation. From what I have experienced, the editors are weak. They are not ready for customer facing applications.Vary
@Pangea: that is maybe because oAW is two years no more maintained. Xtext is a rewrite, it reached 1.0 in last Eclipse release train (Galileo). The tool is perfect fit for the use case - it offers validations and auto-complete, outline, hyperlinking, quickfixes, highlighting and much more. Most of these things would never be possible to do as an internal DSL using any of languages suggested.Beard
@Gabriel thx for this update. I will look into this now. Appreciate if you can point me to the articles and examples of the DSLs created using new Xtext.Vary
@Pangea some good examples can be found on the official Xtext page here: eclipse.org/Xtext/communityBeard
Xtext is mature. And it's actively maintained and enhanced. If you need professional help I can also recommend Itemis, the company "behind" Xtext (I'm not affiliated with them at all).Catchword
C
2

I would recommend Groovy for that.

Colunga answered 24/1, 2011 at 4:21 Comment(0)
G
0

I'll suggest jruby. I've done a few and it's always been pretty easy to get about what I want.

http://www.artima.com/rubycs/articles/ruby_as_dsl3.html

Greenhorn answered 24/1, 2011 at 4:52 Comment(0)
L
-2

Sounds like a problem for Apache Velocity templating engine. It is a Java library with a templating syntax or DSL if you will.

Loggia answered 24/1, 2011 at 4:18 Comment(2)
I need a DSL. Templating engine is not an option. Idea is for user to create the strings using this DSL. I already looked at Velocity, StringTemplate etc.Vary
So what do figure is a DSL? Velocity has a language, which is particularly good for generating text content. It is a Domain Specific Language. If you have specific requirements that aren't met by a templating engines and their languages, you may want to better describe what those requirements are.Loggia

© 2022 - 2024 — McMap. All rights reserved.