Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » XText 2.9 Generated Scope Provider Class
XText 2.9 Generated Scope Provider Class [message #1727714] Fri, 25 March 2016 16:16 Go to next message
Jack Burns is currently offline Jack BurnsFriend
Messages: 4
Registered: March 2016
Junior Member
Hello everyone,

I'd like to know how the default generated scoping provider class is supposed to be used. Earlier versions of XText used AbstractDeclarativeScopeProvider and that was quite easy to understand and use.

Let's say I have the following grammar:
grammar org.xtext.example.mydsl.MyDsl with org.eclipse.xtext.common.Terminals

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

Model:
	((things+=Thing) | (refs+=Reference))*
;
	
Thing:
	'thing' name=ID '{'
		stuff += Stuff* 
	'}'
;

Stuff:
	'stuff' name=ID
;

Reference:
	'reference' thing=[Thing] stuff=[Stuff] 
;


For the Reference clause to work, I need a scope provider.

XText 2.9 generates the following scope provider code for you (in MyDslScopeProvider.xtend):

class MyDslScopeProvider extends AbstractMyDslScopeProvider {
}


AbstractMyDslScopeProvider has no methods of it's own, it just inherits from DelegatingScopeProvider.

I can't wrap my head around how this works or where the code for the scope lookup should go. The "documentation" doesn't really help, because there's only useless code snippets instead of a complete working example.


Pre 2.9 it would have been:
class MyDslScopeProvider extends AbstractDeclarativeScopeProvider {
    def IScope scope_Reference_stuff(Reference reference, EReference ref) {
        scopeFor(reference.thing.stuff)
    }
}


Can someone please enlighten me on how the new scope provider mechanism is supposed to be used?
Re: XText 2.9 Generated Scope Provider Class [message #1727774 is a reply to message #1727714] Sun, 27 March 2016 08:33 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi this work only in you Inherit from AbstractDeclarativeScopeProvider.
Of Not you have to Override the getScope Method and do ifElse on the Parameters.


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:error in creation of new project EMF Generator Model
Next Topic:Import objects from XMI-based model into my DSL
Goto Forum:
  


Current Time: Fri Apr 19 17:11:59 GMT 2024

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

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

Back to the top