Friday, December 18, 2009

Referencing metamodels in Xtext and using them in xpand

There are quite a few resources out there what you need to do if you want to reference a DSL in another DSL, say you need to refer from BDSL to metamodel types of ADSL.

In short you need to figure out how to configure your xtext project (add a dependency to ADSL and sort out the genmodels attribute in the xtext configutaration, more about that here) and you need to find out when to use the platform URI and classpath URI specifications to refer to the metamodels and imported models. And there is the importURI attribute which takes cares of importing your model into another model.

All that can be found in the documentation and various other resources of Xtext, however it took a good deal of time to find out how to make xpand (aka the "Generator" ) recognize your combined model. I always had all kinds of exceptions, basically stating that the xpt templates do know nothing about your referenced model, even so everything works fine in the editor.

The solution is short and simple. You just need to add a line in the MWEReader component of the workflow:

<component class="org.eclipse.xtext.MweReader">
<register class="namespace.of.BDLStandaloneSetup"/>
<register class="namespace.of.ADSLStandaloneSetup"/>

... blablabla

The line for BDSL will already be present, you just need to add the extra line. And maybe you will also need to register the generated EPackages to the StandaloneBean, as usual.

No comments:

Post a Comment