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
Eclipse UserFriend
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
Eclipse UserFriend
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
Eclipse UserFriend
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] by Moderator

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
Eclipse UserFriend
HI, you can have only one level of grammar hierarchy,
so you would need to introduce a basebase grammar0
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
Eclipse UserFriend
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] by Moderator

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
Eclipse UserFriend
in standalone mode:
make sure
- all sandalone setups are called (directly or indirectly).
- you add ALL resources to the resourceset manually before resolving
Previous Topic:Xtend + tycho maven + JDK 17 ==> java.lang.IllegalArgumentException:
Next Topic:Xtext 2.36.0.M1 is out
Goto Forum:
  


Current Time: Mon Feb 10 05:08:35 GMT 2025

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

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

Back to the top