Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Scope filtering across Xtext expressions (Looking to adjust a scoping logic to work across Xtext expressions)
Scope filtering across Xtext expressions [message #1763932] Tue, 23 May 2017 07:53 Go to next message
Pierre Lamy is currently offline Pierre LamyFriend
Messages: 6
Registered: December 2016
Junior Member
As far as this issue is concerned, our current Xtext grammar is articulated around the two below expressions:

MdlProjectionRule:
	'projection' 'rule' MdlNamed MdlDefinable
	(references += MdlRegulatoryReference)*
	'for' 'target' target=MdlProjectionTarget
	'when' when=MdlExpression
	'map' from=MdlTestExpression 'to' to=[MdlSynonym]
	(mapping += MdlProjectionMapping)*
;

MdlProjectionTarget:
	target=MdlSynonymSource
;


We then have an associated Xtend Scope Provider class which filters the values exposed in the 'to=[MdlSynonym]' expression as a function of the value stated as part of the 'target=MdlProjectionTarget' argument.

class MdlScopeProvider extends AbstractMdlScopeProvider {

	@Inject MdlTypeProvider typeProvider
	@Inject extension MdlExtensions
	
	override getScope(EObject context, EReference reference) {
		switch reference {
		    case MdlPackage.Literals.MDL_PROJECTION_RULE__TO: {
		    if(context instanceof MdlProjectionRule) {
		       val rootElement = EcoreUtil2.getRootContainer(context)
                       val candidates = EcoreUtil2.getAllContentsOfType(rootElement, MdlSynonym)
                       val filtered = candidates.filter([source.getName() == context.target.target.getName()])
                       val allSynonyms = Scopes.scopeFor(filtered)
                    return allSynonyms
				}
				return IScope.NULLSCOPE
			}
		}
		super.getScope(context, reference)
	}


While this is working well, I am struggling to adjust the Xtend scoping syntax in order to provide for the Xtext grammar to support multiple mapping entries, as shown below:
MdlProjectionRule:
	'projection' 'rule' MdlNamed MdlDefinable
	(references += MdlRegulatoryReference)*
	'for' 'target' target=MdlProjectionTarget
	'when' when=MdlExpression
//	'map' from=MdlTestExpression 'to' to=[MdlSynonym]
	(mapping += MdlProjectionMapping)*
;

MdlProjectionTarget:
	target=MdlSynonymSource
;

MdlProjectionMapping:
	'map' from=MdlTestExpression 'to' to=[MdlSynonym]
;


I understand that the Xtend scoping logic should now point to the MdlProjectionMapping expression as a context, but I am not able to properly adjust the filtering part of the syntax (i.e. the prior expression which has been replaces by ??? in the below code snippet).

I took note of the Xtext Scoping documentation, and focused on the superElement cross-reference which seems to be a related use case... but to no effect so far.

			case MdlPackage.Literals.MDL_PROJECTION_MAPPING__TO: {
				if(context instanceof MdlProjectionMapping) {
					val rootElement = EcoreUtil2.getRootContainer(context)
                    val candidates = EcoreUtil2.getAllContentsOfType(rootElement, MdlSynonym)
                    val filtered = candidates.filter([source.getName() == (????.getName()])
                    val allSynonyms = Scopes.scopeFor(filtered)
                    return allSynonyms
				}
				return IScope.NULLSCOPE
			}


Your guidance would be greatly appreciated to help me overcoming this hurdle!
Re: Scope filtering across Xtext expressions [message #1763999 is a reply to message #1763932] Tue, 23 May 2017 20:32 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
hmmm i am not sure if i can follow you.

you can use object.eContainer() or EcoreUtil2.getContainerOfType(object, Type.class) to navigate from an element to its parent.
thus you should be able to find the contexts parent of type MdlProjectionRule (if that is what you are looking for)


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Scope filtering across Xtext expressions [message #1766425 is a reply to message #1763999] Wed, 21 June 2017 10:36 Go to previous message
Pierre Lamy is currently offline Pierre LamyFriend
Messages: 6
Registered: December 2016
Junior Member
Christian,
Thank you for the pointer. I used the EcoreUtil2.getContainerOfType(object, Type.class) approach and it worked.
Previous Topic:How to get a SemanticSyntaxHighlighter to run
Next Topic:xtext/xbase data flow analysis
Goto Forum:
  


Current Time: Tue Mar 19 02:57:21 GMT 2024

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

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

Back to the top