Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Use one grammar within another grammar
Use one grammar within another grammar [message #1010228] Sat, 16 February 2013 18:42 Go to next message
Christian Franzen is currently offline Christian Franzen
Messages: 2
Registered: February 2013
Junior Member
Hi guys.

I have a problem with combining two languages with Xtext. I already have two grammars. The first one is the Java Expression Language and allows me to write expressions like

${aaa + 1}
${obj.method().getMe()}


That is working fine. Now I want to use that grammar within another grammer so that I am able to do things like that:

SET var = ${aaa + 1}


The left site of the equals sign is my first grammer, the rest is my second grammar. How can I do that? I tried to do it with grammar mixin. So I added the following to my second grammar:

import "http://www.mystuff.eclipse.org/el/text/ElDef" as elDef

...

SetStatement:
    'SET' name=ID '=' el=[elDef::ElStatement];


I also adopted my MANIFEST.MF and registered the first grammer in my .mwe2 file:

registerGeneratedEPackage = "org.eclipse.mystuff.el.text.elDef.ElDefPackage"
registerGenModelFile = "platform:/resource/org.eclipse.mystuff.el.text/src-gen/org/eclipse/mystuff/el/text/ElDef.genmodel"


Everything is generated without an error and I am able to edit files with the editor of my second grammar. But I can not use the first grammar within the second one. When i write the line

SET var = ${aaa + 1}


in my editor of the second grammar, I get the error message "Couldn't resolve reference to ElStatement 'aaa'". Any idea what I am doing wrong here?

Regards
Christian
Re: Use one grammar within another grammar [message #1010491 is a reply to message #1010228] Sun, 17 February 2013 08:19 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian Dietrich
Messages: 6198
Registered: July 2009
Senior Member
Hi,

what you did is a cross reference: => you can refer to an element of a file of the other grammar by name.
the only way to resuse rule from another grammar in inheritance. (as it is done with grammar org.xtext.example.mydsl.MyDsl with org.eclipse.xtext.common.Terminals)

~Christian
Re: Use one grammar within another grammar [message #1013513 is a reply to message #1010491] Sat, 23 February 2013 16:18 Go to previous message
Christian Franzen is currently offline Christian Franzen
Messages: 2
Registered: February 2013
Junior Member
Thanks for you reponse and the clarification. Didn't understand the grammar-mixin feature correctly.
Previous Topic:cross references and the next rule without keyword
Next Topic:Using Actions Correctly in Xtext
Goto Forum:
  


Current Time: Wed Aug 20 14:43:52 EDT 2014

Powered by FUDForum. Page generated in 0.01477 seconds