仅限定具有限定名称的先前元素的范围
Scoping only previous elements with qualified name
我正在尝试使用家庭自动化示例来理解 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)
}
}
如何取回美国的合格名称?
查看作用域中的其他方法class。
@Inject IQualifiedNameProvider qnp
....
Scopes.scopeFor(list, qnp, IScope.NULLSCOPE)
我正在尝试使用家庭自动化示例来理解 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)
}
}
如何取回美国的合格名称?
查看作用域中的其他方法class。
@Inject IQualifiedNameProvider qnp
....
Scopes.scopeFor(list, qnp, IScope.NULLSCOPE)