Which language (which runs on the JVM) is best for creating DSL?

We have a requirement to create complex strings with a fixed length and a variable length. These lines can be a customer profile, order, etc. What JVM-based programming language do you offer?

The idea is for the end user to create strings using this DSL. So I'm looking for confirmation, code completion, etc.

+8
java architecture jvm dsl
source share
8 answers

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

+5
source share

Use Lisp , which runs on the JVM. Some options that you have:

There is a good free book that explains how to use Lisp to develop software from the bottom up, that is, how to grow Lisp into a language that is ideal for solving a problem.

Languages ​​in the Forth family are also great for defining DSLs. Several work on the JVM:

+7
source share

There are two types of DSL; external and built-in.

The external DSL is completely separate from your host language, that is, you write it outside the language, but is usually used to generate code in the host language. For this approach, XText with XPand is probably the best tool since a simple grammar file generates a full Eclipse editor for the new DSL, and you can use XPand's code templates to generate the actual Java code. XTend and XPand are written in Java, but this is accidental, as they can be written in everything while you finish the Java code at the end of the process. The disadvantage of this approach is that for any fairly complex problem, the language will become quite complex, and it will take a lot of work in grammar and even more in templates for generating code. You cannot use any features of the host language, such as evaluating expressions, so all this requires recovery in DSL if you need it. XText will soon include XBase, which is a partial language that will contain expressions that will help here.

Another approach is the built-in DSL, where higher-level domain functions are expressed in the host language or with higher-order constructs (e.g. HOF and monads), which are usually found in functional languages ​​or through metaprogramming objects such as macros (e.g. Lisp). Java none of them is a bad choice for DSL (or most other forms of abstract programming) to work. Spring Roo offers a metaprogram type tool for Java using generation, so it may be an option. Otherwise, Scala is probably the most popular in Java, as the JVM language, and has the features you need.

Embedded DSLs are usually much simpler than external DSLs because you have full host language support, so I recommend trying Scala.

+6
source share

Scala completely! Scala is particularly suitable for internal DSLs (see this ).

+4
source share

I would recommend Groovy for this.

+2
source share

I suggest jruby. I did a few and it was always very easy for me to get what I want.

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

0
source share

Sounds like a problem to the Apache Velocity template engine. This is a Java library with template syntax or DSL if you do.

-2
source share

Source: https://habr.com/ru/post/651424/


All Articles