Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Mix more than one grammar elements in another grammar(Grammar mixins)
Mix more than one grammar elements in another grammar [message #1867527] Thu, 27 June 2024 11:28 Go to next message
Shashi Mising name is currently offline Shashi Mising nameFriend
Messages: 50
Registered: August 2011
Member
Hello,

I have 3 different grammars for 3 different file extensions.
Let's say Grammar1, Grammar2 and Grammar3.

Grammar1 is extending an Grammar2 using 'with' keyword already to refer an grammar2 elements in grammar1.

Now i also need to refer an grammar3 elements in grammar1. How can i do this?

As xtext supports only one level of inheritance i cannot extend grammar3 from grammar1.

Re: Mix more than one grammar elements in another grammar [message #1867530 is a reply to message #1867527] Thu, 27 June 2024 11:42 Go to previous messageGo to next message
Tamas Miklossy is currently offline Tamas MiklossyFriend
Messages: 160
Registered: February 2016
Senior Member
Hello Shasi!

You can try to import the things you need, similar to https://github.com/eclipse/gef/blob/master/org.eclipse.gef.dot/src/org/eclipse/gef/dot/internal/language/Dot.xtext#L33

Hope that helps!
Tamás
Re: Mix more than one grammar elements in another grammar [message #1867533 is a reply to message #1867530] Thu, 27 June 2024 11:49 Go to previous messageGo to next message
Shashi Mising name is currently offline Shashi Mising nameFriend
Messages: 50
Registered: August 2011
Member
Thanks Tamas.

But if i import and refer the grammar3 elements in grammar1 , the cross reference is not working, grammar3 elements are not resolving.

And Grammar3 is in a different plugin part of different repository

[Updated on: Thu, 27 June 2024 12:05]

Report message to a moderator

Re: Mix more than one grammar elements in another grammar [message #1867548 is a reply to message #1867533] Thu, 27 June 2024 14:16 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14698
Registered: July 2009
Senior Member
HI, you can have only one level of grammar hierarchy,
so you would need to introduce a basebase grammar0


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Mix more than one grammar elements in another grammar [message #1867620 is a reply to message #1867548] Tue, 02 July 2024 05:13 Go to previous messageGo to next message
Shashi Mising name is currently offline Shashi Mising nameFriend
Messages: 50
Registered: August 2011
Member
Cross references are resolving properly in UI mode but not in command line mode.

In grammar1 scope provider i implemented a method to resolve grammar3 elements and method implementation is as below.

Method getGrammar3Elements(){

Injector injector =
Grammar3StandaloneSetup().createInjectorAndDoEMFRegistration();

ResourceSet resourceSet = injector.getInstance(XtextResourceSet.class);

URI fileURI = URI.createFileURI(fileUri);

Resource resource = resourceSet.getResource(fileUri, true);

EObject data = resource.getContents().get(0);

This method works fine in UI mode return the grammar3 elements and references are resolving as expected.

BUT if i run in command line mode, not getting any response from the LINE - resourceSet.getResource(fileUri, true);

What is an issue here?

}

[Updated on: Tue, 02 July 2024 05:26]

Report message to a moderator

Re: Mix more than one grammar elements in another grammar [message #1867623 is a reply to message #1867620] Tue, 02 July 2024 07:05 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14698
Registered: July 2009
Senior Member
in standalone mode:
make sure
- all sandalone setups are called (directly or indirectly).
- you add ALL resources to the resourceset manually before resolving


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:Xtend + tycho maven + JDK 17 ==> java.lang.IllegalArgumentException:
Next Topic:Xtext 2.36.0.M1 is out
Goto Forum:
  


Current Time: Sat Jul 20 02:02:44 GMT 2024

Powered by FUDForum. Page generated in 0.04946 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top