变量应该只显示在xtext中的函数

时间:2013-04-24 07:12:09

标签: java eclipse eclipse-plugin eclipse-cdt xtext

我的输出文件:

reg1 {
field a field b
}

reg2 {
field c field d
}

FOREACH ( X IN reg1 ) {
X . a
}

FOREACH ( Y IN reg2 ) {

现在在此之后,如果我执行ctrl + space,我预计只会弹出Y.但X和Y都在弹出。 如何将X限制为第一个FOREACH循环?在第一个FOREACH循环X中,它的值应该被删除。请有人建议我如何实现这个?

相关的语法规则是:

Model:
entities+=Entity+
uses+=Use+
;
Entity:
name=ID "{"
attributes+=Attr+
"}"
;
Attr:
"field" name=ID
;
Use:
"FOREACH" var=conds "{"
varref=[cond] "." attr=[Attr]
"}"
;
conds:
"(" cond1=cond ")"
| "," cond2=cond
;
cond:
name=ID "IN" entity=[Entity]
;

范围提供者:

public class MyDslScopeProvider extends AbstractDeclarativeScopeProvider {
IScope scope_Use_attr(Use ctx , EReference ref) {
return Scopes.scopeFor(ctx.getVarref().getEntity().getAttributes());
}
}

1 个答案:

答案 0 :(得分:1)

您是否在您的范围实施中添加了断点?您可以为attr定义范围实现,但不能为语法的varref定义范围实现。沿着这些线添加实现将起到作用。

IScope scope_Use_varref(Use ctx, EReference ref) {
  return Scopes.scopeFor(Collections.singleton(ctx.getVar().getCond1()));
}

请注意,解析器规则conds似乎是假的。