Sunday, August 29, 2010

Fun with Xtext: Language Mixins

There are rumors that Xtext does only have rudimentary support for language libraries or language reuse and does not allow to create 'advanced stuff'. And it is actually true, that Xtext has only first class support for extending only one other language. But with some creativity and customizing, it is easily possible to create really nice editors for intermixed languages. I've produced a small screencast that demonstrates how an editor for template proposals (read: a template language) may look like when it's aware of your target syntax.

Besides the smart editor for template proposals there is another interesting feature in this screencast: As template proposals are usually edited on a preference page, I implemented a small prototype that shows how a form field may leverage the features of a full blown Xtext editor.

Both prototypic implementations are only based on Xtext 1.0 APIs and not yet publicly available. But I'ld assume that at least parts of them will be moved into the Xtext Indigo stream. Stay tuned!


Jan Köhnlein said...

Awesome. Looking forward to adapt that in combination with graphical editors!

Markus Voelter said...


any chance you can share with us how these kinds of mixins are actually implemented :-) ?


Sebastian Zarnekow said...

Hi Markus,

the implementation is based on customized syntax highlighting, content assist and validation and delegates to the respective services of the "injected" language.


knut said...

Very cool! Looking forward to see this as part of Xtext.

Of course not every language has the "luxury" of having unique tokens marking the beginning and end of mixin partitions. Or can you even write templates for the template language? :-)

Sebastian Zarnekow said...


yes, templates for templates are possible. All you need is an escape character for the template body. IIRC it should look like this:

templates for org...Templates
newTemplate(..) for Template <<
${name} (..) for ${CrossRef} \<<