Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » How to restrict available objects
How to restrict available objects [message #792764] Tue, 07 February 2012 11:34 Go to next message
Tobi Miller is currently offline Tobi MillerFriend
Messages: 12
Registered: January 2012
Junior Member
Hello,
I have a little problem with my new language editor. I have declared a language. In the following I will provide the relevant code:

Formatting: {Formatting}
	'FORMATTING'
	'{'
		(formats += Format)*
		(objects += Object)*
	'}'
;

FORMAT:
	'FORMAT' name = ID value = STRING
;

ATTFORMAT:
	'ATTFORMAT' value = [FORMAT]
;

Object:
	'OBJECT' name = ID
	'{' 
		(attformats = ATTFORMAT)?
	'}'
;


What I want to do with this grammar:
FORMATTING 
{
    FORMAT format1 "test"
    FORMAT format2 "test2"

    OBJECT obj1
    {
        ATTFORMAT format1
    }
}


I want to be able to create code blocks as mentioned above. The critical part ist in the OBJECT block at the ATTFORMAT attribute there should be references of the FORMAT attributes specified ONLY in the FORMATTING block that is surrounding the OBJECT block. Even this works. But if I have multiple files with FORMATTING blocks and FORMAT attributes in my project, the editor offers me all FORMAT attributes from all files. I want only the ones of the current file. How can I restrict that?
Re: How to restrict available objects [message #792786 is a reply to message #792764] Tue, 07 February 2012 12:10 Go to previous messageGo to next message
Meinte Boersma is currently offline Meinte BoersmaFriend
Messages: 434
Registered: July 2009
Location: Leiden, Netherlands
Senior Member
You can restrict that using scoping, meaning choosing an appropriate global scoping fragment and/or implementing custom scoping. This is explained in the Reference Manual. Keep in mind that qualified naming plays a large role in scoping since matching happens through qName.

Re: How to restrict available objects [message #792795 is a reply to message #792786] Tue, 07 February 2012 12:23 Go to previous messageGo to next message
Tobi Miller is currently offline Tobi MillerFriend
Messages: 12
Registered: January 2012
Junior Member
Hmm, in the reference manual at 'scoping' I read that by default only instances from the current resource are searched... Do you mean I have to prevent in my scope provider that other resources are referenced?
Re: How to restrict available objects [message #792802 is a reply to message #792795] Tue, 07 February 2012 12:29 Go to previous messageGo to next message
Meinte Boersma is currently offline Meinte BoersmaFriend
Messages: 434
Registered: July 2009
Location: Leiden, Netherlands
Senior Member
Uh, http://www.eclipse.org/Xtext/documentation/2_1_0/080-scoping.php says rather a bit more about scoping than that. First of all, you have to think which global scope provider you should configure in relation to which qualified naming scheme. This usually takes care of about 75% of the desired behavior. After that, you'll have to see what you still need to configure in terms of local scoping. You can start with the local scoping but you'd probably end up implementing stuff which the appropriate global scope provider takes care of out-of-the-box.

Re: How to restrict available objects [message #792811 is a reply to message #792802] Tue, 07 February 2012 12:43 Go to previous messageGo to next message
Tobi Miller is currently offline Tobi MillerFriend
Messages: 12
Registered: January 2012
Junior Member
I read it again and I think I have to use the AbstractDeclarativeScopeProvider. This is the only cross reference I have and the only thing that matters in scoping context... But I think I'm too stupid to understand the documentation. I think I need an example... Trying to find one...
Re: How to restrict available objects [message #792843 is a reply to message #792811] Tue, 07 February 2012 13:34 Go to previous message
Tobi Miller is currently offline Tobi MillerFriend
Messages: 12
Registered: January 2012
Junior Member
That brought the solution!

public class DEFScopeProvider extends AbstractDeclarativeScopeProvider {
	IScope scope_FORMAT(Formatting ctx, EReference ref) {
		if (ctx.getFormats() == null) {
			return IScope.NULLSCOPE;
		} else {
			return Scopes.scopeFor(ctx.getFormats());
		}
	}
}
Previous Topic:Couldn't find EReference for crossreference org.eclipse.xtext.impl.CrossReferenceImpl
Next Topic:Debug grammar generation gives error but seems to work
Goto Forum:
  


Current Time: Mon Apr 06 00:22:44 GMT 2020

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

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

Back to the top