例如
我有一个这样的语法:
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
喜欢:Service "ServiceName" for car1
Service "ServiceName" for car2 (extra1 extra2)
我如何解决对
Extras
的引用的 Car
?
最佳答案
这可以通过简单的交叉引用来完成
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)
}
}
关于reference - Xtext:对属性的 DSL 引用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21306822/