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.

Adeel Ansari
  • 39,541
  • 12
  • 93
  • 133
Aravind Yarram
  • 78,777
  • 46
  • 231
  • 327

8 Answers8

8

Groovy

http://docs.codehaus.org/display/GROOVY/Writing+Domain-Specific+Languages

hhafez
  • 38,949
  • 39
  • 113
  • 143
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
Vijay Mathew
  • 26,737
  • 4
  • 62
  • 93
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.

Andrew
  • 993
  • 9
  • 11
5

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

01es
  • 5,362
  • 1
  • 31
  • 40
5

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

Henrik
  • 3,757
  • 1
  • 19
  • 18
  • 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. – Aravind Yarram Jan 24 '11 at 20:55
  • 1
    @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. – Gabriel Ščerbák Jan 25 '11 at 00:26
  • @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. – Aravind Yarram Jan 25 '11 at 00:31
  • @Pangea some good examples can be found on the official Xtext page here: http://www.eclipse.org/Xtext/community/ – Gabriel Ščerbák Jan 25 '11 at 01:27
  • 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). – Henrik Feb 02 '11 at 14:37
2

I would recommend Groovy for that.

Adeel Ansari
  • 39,541
  • 12
  • 93
  • 133
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

xaxxon
  • 19,189
  • 5
  • 50
  • 80
-2

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

Konstantin Komissarchik
  • 28,879
  • 6
  • 61
  • 61
  • 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. – Aravind Yarram Jan 24 '11 at 04:26
  • 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. – Konstantin Komissarchik Jan 24 '11 at 04:39