开发者

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

开发者 https://www.devze.com 2023-02-06 14:24 出处:网络
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

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.


Groovy

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


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


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.


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


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


I would recommend Groovy for that.


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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消