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!