Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Adding definition in global scope provider
Adding definition in global scope provider [message #1753282] Fri, 03 February 2017 10:08 Go to next message
chris yo is currently offline chris yoFriend
Messages: 146
Registered: February 2013
Senior Member
I tried to create a jar to add it as a plugin but it is more complicated than I thought. Thus, I decided to change the global scope provider instead. But I did not have much luck in adding the definition to the global scope provider manually.
There are some entries that are added only during generator part as the user does not need to specify it.

Hello admin age 99!
Hello sample age 2!
Bye sample ! see you  sept;


my grammar is:
grammar org.xtext.example.mydsl.MyDsl with org.eclipse.xtext.common.Terminals

generate myDsl "http://www.xtext.org/example/mydsl/MyDsl"

Model:
	greetings+=(Greeting| Test)*;
	
Greeting:
	'Hello' sample=[Test] 'age' age=INT '!';
Test:
	'Bye' sName=ID '!' 'see' 'you' date=ID ';'
;

I called MydslFactory::eInstance.createGreeting and set the variables in main.java before all the resource are loaded, but the error is still there. Are there any articles that shows how to do it in global scope provider and resource service provider?

Re: Adding definition in global scope provider [message #1753287 is a reply to message #1753282] Fri, 03 February 2017 10:23 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 11093
Registered: July 2009
Senior Member
whats the problem with the libary approach in the first place? is it your main method? what do you there? it should be no problem to traverste the lib jar directly or indirectly there

there is no tutorial.
many years ago i did something like (dont know if this still works)

public class MyDslGSP extends DefaultGlobalScopeProvider {

	@Inject
	IResourceDescription.Manager mgr;

	@Override
	public IScope getScope(Resource resource, EReference reference, Predicate<IEObjectDescription> filter) {
		URI libaryResourceURI = URI.createURI("dummy://demo/test.mydsl");
		Resource libaryResource = resource.getResourceSet().getResource(libaryResourceURI, false);
		if (libaryResource == null) {
			System.out.println("LOOOOOOOOAAAAADDDDD");
			libaryResource = resource.getResourceSet().createResource(libaryResourceURI);
			try {
				libaryResource.load(new StringInputStream("Hello Libary1! Hello Libary2 from Libary1!"), null);
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		IResourceDescription resourceDescription = mgr.getResourceDescription(libaryResource);
		Iterable<IEObjectDescription> libary = resourceDescription.getExportedObjects();
		return new SimpleScope(super.getScope(resource, reference, filter), libary, false);
	}

}


Need professional support for Xtext, Xpand, EMF?
Go to: http://xtext.itemis.com
Twitter : @chrdietrich
Blog : christiandietrich.wordpress.com
Re: Adding definition in global scope provider [message #1753717 is a reply to message #1753287] Thu, 09 February 2017 09:32 Go to previous messageGo to next message
chris yo is currently offline chris yoFriend
Messages: 146
Registered: February 2013
Senior Member
Hi Christian,
Thanks this works for me. I added this in my main.java though. The library approach did not work for me because I usually export a jar file, and don't know how to create a plugin.
Re: Adding definition in global scope provider [message #1753719 is a reply to message #1753717] Thu, 09 February 2017 09:40 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 11093
Registered: July 2009
Senior Member
hi i still cannot folow your problem.
as i said the solution would be much cleaner.


Need professional support for Xtext, Xpand, EMF?
Go to: http://xtext.itemis.com
Twitter : @chrdietrich
Blog : christiandietrich.wordpress.com
Previous Topic:[SOLVED] Where is FormatterTestHelper?
Next Topic:Mutliline string concatenation
Goto Forum:
  


Current Time: Wed Aug 23 21:52:37 GMT 2017

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

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