I was hoping that by now there would be some "how-to" available online; but Google search hasn't come up with anything useful. Hence, here is a short description of how a Mixin can be done:
So, what is a Mixin? Assume that you have two Xtext grammars: A and B. As long as A and B are independent of each other, you don't need Mixins. Now, let's assume that grammar A references elements that are described in grammar B or simply extends grammar B. In that case you need to tell grammar A about grammar B.
If you consult the Xtext documentation you won't get very far. To correct that here is what you need to do:
- Create Xtext projects for both grammar A and grammar B (you probably already did this)
- Add a plug-in dependency of A's Xtext project to B's Xtext project
- Edit the
A.xtext
file to include the following statement:
import "platform:/resource/B/src-gen/
<B's package>/B.ecore" as B
(This must be locatedbefore thegenerate
statement!)
- Edit
GenerateA.mwe2
file to add the reference to B's genmodel by inserting:
referencedGenModels = "classpath:/
<B's package>
/B.genmodel"
intoecore.EcoreGeneratorFragment
fragment.
- Re-Generate A's Xtext project by running
GenerateA.mwe2
Everything works fine, but I can use B's model elements only with "returns" statements like:
ReplyDeleteMyParserRule returns B::OtherRule:
bla, bla bla
;
How can I write statements like
grammar A with B ?