Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Problem with customized scoping
Problem with customized scoping [message #1580471] Fri, 23 January 2015 14:10 Go to next message
Johannes Tempel is currently offline Johannes TempelFriend
Messages: 3
Registered: January 2015
Junior Member
Hi,

i have a problem with my implementation of scoping, i want to list unique IDs from different scopes with their parent names to ensure they are unique in the list but it does not work.

Here is an example DSL with the problem:
grammar org.xtext.scopeproblem.mydsl.MyDsl with org.eclipse.xtext.common.Terminals
generate myDsl ".../scopeproblem/mydsl/MyDsl"

Model:
	summeries=Summary
	collections=Collection;
	
Summary:
	'summery' name=ID 'collection' collection=[Collection|ID]'{'
		fileTypeList=FileTypeList?
	'}';
	
FileTypeList:
	'filetypes' '{'	
		fileTypes+=[FileType|ID] (',' fileTypes+=[FileType|ID])*
	'}';

Collection:
	'Collection' name=ID '{'
		files+=File+
	'}';

File:
	'file' name=ID '{'
		fileTypes+=FileType';' (fileTypes+=FileType';')*
	'}';

FileType:
	name=ID;


And here is the scope provider:
class MyDslScopeProvider extends org.eclipse.xtext.scoping.impl.AbstractDeclarativeScopeProvider {

	def IScope scope_FileTypeList_fileTypes(FileTypeList context, EReference reference){
		
		val sum = context.eContainer
		if (sum instanceof Summary) {
			val mod = sum.eContainer
			if (mod instanceof Model) {
				var LinkedList<FileType> filetypeList = new LinkedList<FileType>()
				for( File file : (mod as Model).collections.files) {
					filetypeList.addAll(file.fileTypes)
				}
				return Scopes.scopeFor(filetypeList, Scopes.scopeFor((mod as Model).collections.files))
			}
		}
		return IScope.NULLSCOPE
	}
}


And this is the model:
summery sum collection collect1 {
	filetypes {
		f1,
		f2,
		f3
	}
}

Collection collect1 {
	file files1 {
		f1;
		f2;
	}
	
	file files2 {
		f1;
		f3;
	}
}


The problem is, f1 in collect1 referes to f1 in files1, it is not possible to make a reference to f1 from files2.
How can i tell the scoping to use the full qualified name like "collect1.files2.f1"?

Thank you
Re: Problem with customized scoping [message #1601170 is a reply to message #1580471] Wed, 04 February 2015 19:38 Go to previous message
Sven Efftinge is currently offline Sven EfftingeFriend
Messages: 1823
Registered: July 2009
Senior Member
The important thing you need to do is, to allow a syntax for fully qualified names in the cross reference:

FileTypeList:
'filetypes' '{'
fileTypes+=[FileType|QualifiedName] (',' fileTypes+=[FileType|QualifiedName])*
'}';

QualifiedName : ID ('.' ID)*;

Now you can create scopes using the qualified names.
Previous Topic:XtextCON 2015 - Call For Submissions
Next Topic:xtext validation (warning method) information needed
Goto Forum:
  


Current Time: Fri Apr 26 05:46:10 GMT 2024

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

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

Back to the top