Reference Xtext:DSL对属性的引用

Reference Xtext:DSL对属性的引用,reference,grammar,dsl,xtext,Reference,Grammar,Dsl,Xtext,比如说 我有这样一个语法: 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+=Ref

比如说

我有这样一个语法:

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 
;
在我的模型中,我想创建一个
服务
,比如:

Service "ServiceName" for car1
Service "ServiceName" for car2 (extra1 extra2)

如何解析对
汽车的
附加
的引用?

这可以通过简单的交叉引用来完成

Service:
    'Service' att=STRING 'for' car=[Car] ('(' extras+=[Extra]+ ')')?
;
和相应的作用域提供程序

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)
    }

}