Wednesday, July 11, 2012

Seven Languages in Seven Weeks!

Xtext 2.3 is out and with it are seven cool example languages we’ve built during the last weeks. We built them so you can learn the ideas behind the new API to implement JVM-based languages. The languages are all at github ready to be cloned and tried out including working examples and comprehensive documentation. Let me briefly introduce the examples:

A Scripting Language

What’s a scripting language? Well, basically just a language which lets you start coding without any boilerplate class declaration or main method craziness.

A Logo clone (little tortoise)

And finally a fun Logo-clone which shows how to use the interpreter.

A Build Language

When I saw Gradle the first time my thought was: This can be done in a much nicer way with Xtext. So here’s the proof:

MongoDB Documents

MongoDB is designed for schema less (read untyped languages). That’s perfectly ok and sometimes even useful. But: when you use it from Java things start to become ugly: Java is just a bad fit for generic data structures such as JSON which is why there are endless mapper frameworks and the like to bridge the gap between typed and untyped. The DSL we built is hybrid, in that it’s just a static facade over the still dynamic MongoDB document and it still provides the generic API as well.

Guice Modules

Xtext is powered by Guice and it’s a great framework. This languages lets you describe Guice modules in a declarative way with static analysis and further possibilities to generate ready to use injectors.

Http Routing

This is a little language that lets you dispatch incoming HTTP requests. It’s very similar to the DSL used in Play! but is built to be used together with dependency injection.

Template Language

A template language for HTML, which demonstrates how to add new expressions.

7 comments:

  1. Regarding to "A Build Language" I want you to point to http://svn.apache.org/repos/asf/ant/sandbox/antdsl/

    ReplyDelete
    Replies
    1. thanks for the pointer. Looks interesting. Do you know who is driving that project?

      Delete
  2. Oh I wish the last two were real!

    You mention specifically play! routes, yet your routing scheme is not play! compatible but invented one. Why not make it work with real play! routes file?

    Last one is another such case, play! happens to also missing highlighting / editor for the *.scala.html files, if it is such a breeze to do it with Xtext why not benefit us all and make the example to work with play! instead of inventing new?

    ReplyDelete
    Replies
    1. The examples are made to give you an idea about what's possible, not to build better tooling for the play! framework.

      Delete
  3. In my experience Xtext is great if you want to create a small dsl from scratch but it not so well suited if you want to create an editor for an existing language or for a more complex language. Then the defaults often do not fit and you end up doing it all manually anyway. What I really miss is a clean AST on which I can define attributes as in jastAdd.

    ReplyDelete
    Replies
    1. You can built arbitrary AST structures, it's just a convenience *option* to have the AST types being derived from the grammar.

      Delete
    2. Most of the infrastructure is applicable to any kind of language. Sigasi (sigasi.com), for instance, have built a VHDL IDE based on Xtext after they built a first version without it. So they know the difference and they are totally happy with using Xtext AFAIK. Another example might be google's protobuf IDE (http://code.google.com/p/protobuf-dt/).

      Delete