Reputation: 1211
For example
i have a grammar like this one:
Bundle:
'Bundle'
name= ID '{'
car+=Car+
service +=Service*
'}'
;
Car:
'Car'
name=ID
extra+=Extra*
'}'
;
Extra:
name= ID '=' type=STRING
;
Service:
'Service' att=STRING 'for' ref+=Reference*
;
Reference:
//Ref to car oder Ref to Car.Extra
;
In my model i want to create a Service
like:
Service "ServiceName" for car1
Service "ServiceName" for car2 (extra1 extra2)
How can i resolve the reference to Extras
of a Car
?
Upvotes: 4
Views: 1730
Reputation: 11868
this can be done with simple cross refs
Service:
'Service' att=STRING 'for' car=[Car] ('(' extras+=[Extra]+ ')')?
;
And a corresponding scope provider
package org.xtext.example.mydsl.scoping
import org.eclipse.emf.ecore.EReference
import org.eclipse.xtext.scoping.IScope
import org.eclipse.xtext.scoping.Scopes
import org.eclipse.xtext.scoping.impl.AbstractDeclarativeScopeProvider
import org.xtext.example.mydsl.myDsl.Service
class MyDslScopeProvider extends AbstractDeclarativeScopeProvider {
def IScope scope_Service_extras(Service ctx, EReference ref) {
return Scopes.scopeFor(ctx.car.extra)
}
}
Upvotes: 4