I am writing a Java program that requires its (technical) users to write scripts that it uses as input; he interprets these scenarios in a sequence of actions and executes them. I'm currently looking for the cleanest way to implement the script / language. Initially, I was thinking of moving along an XML route, but the nature of the required input is actually a procedural, linear flow of actions that needs to be performed:
function move(Block b, Position p) {
Etc. Please note: the above example does not constitute the exact syntax I'm looking for. I am still in the “30,000 feet” phase, and I don’t know what my specific scripting language will look like. I only provide this example to show that this is a thread / procedural script that users should write, and that XML is probably not the best candidate for its implementation.
Perfect for hierarchical data, XML just doesn't seem to be the best choice for such an implementation (although I can get it working if necessary).
Unaware of DSL licking, I started reading Groovy DSL discs and they feel perfect for what I need.
I'm sure I can write, say, Groovy (I'm stronger in Groovy than Scala, JRuby, etc.) DSL, which allows users to write scripts ( .groovy files) that my program could run as input at runtime.
Is this correct, or am I misunderstanding the purpose of DSL? If I'm wrong, does anyone have any suggestions for me? And if I'm right, how will the Java program read and execute the .groovy file (in other words, how .groovy my program “consume” their script)?
Change I like ANTLR. Although I would like to roll up my sleeves and write DSL Groovy, I do not want my users to be able to write any old Groovy program that they want. I want my own “micro language”, and if users go beyond it, I want the interpreter to invalidate the script. It starts to seem that Groovy / DSL is not the right choice, and perhaps ANTLR might be the solution I need ...?