我正在尝试使用家庭自动化示例来理解Xtext范围。语法如下:
grammar org.xtext.homeautomation.Rules with org.eclipse.xtext.common.Terminals
generate rules "http://www.xtext.org/homeautomation/Rules"
Model:
declarations+=Declaration*
;
Declaration :
Device | Rule
;
Device :
'Device' name=ID 'can' 'be'
(states+=State (',' states+=State)*)?
;
State :
name=ID
;
Rule:
'Rule' description=STRING
'when' when=[State|QualifiedName]
'then' then=[State|QualifiedName]
;
QualifiedName :
ID ('.' ID)*
;
我使用以下ScopeProvider来阻止前向引用,但是由此我放弃了限定名称。
class RulesScopeProvider extends AbstractRulesScopeProvider {
override getScope(EObject context, EReference reference) {
if (context instanceof Rule) {
scope_Rule(context, reference)
}
}
def scope_Rule(Rule rule, EReference r) {
var list = (rule.eContainer as Model).declarations as List<Declaration>
var i = list.subList(0, list.indexOf(rule)).filter(typeof(Device)).map[states].flatten
Scopes::scopeFor(i)
}
}
如何恢复各州的合格名称?
答案 0 :(得分:0)
查看Scopes类中的其他方法。
@Inject IQualifiedNameProvider qnp
....
Scopes.scopeFor(list, qnp, IScope.NULLSCOPE)