The "domain" of this example DSL is old-school adventure games like King's Quest.
The post shows the different steps how to transform the following Java-like code...
game.look(); game.go("north"); game.take("dagger"); game.take("sword"); game.take("key"); game.take("axe");
... into the following statements:
look go north take dagger grab sword hold key yoink axe
Both of the above snippets are valid Groovy code that can be executed on the JVM!
To understand and learn about the implementation of internal DSLs I implemented this DSL example.
The project can be browsed and downloaded on my github account. The project is fully mavenized, and should easily be buildable and runnable with Maven.
looks like rather simple message selection to me. what about chaining? could this be done as easily?
ReplyDeleteYoink axe? :-)
ReplyDeleteAnd please, explain why the sword is needed at all if you got an axe.
@Anonymous
ReplyDeleteI have a slight suspicion that you you are a dwarf...
Maybe you could use the sword for grooming you beard?
Hey thanks for the link. I think it's cool that you implemented the DSL.
ReplyDeleteHey
ReplyDeleteThat looks a bit familiar! Check out groovymud,it's an entire multi user dungeon code base written in groovy that uses a very simila dsl to this o_0
http://code.google.com/p/groovymud