1

My output file:

reg1 {
field a field b
}

reg2 {
field c field d
}

FOREACH ( X IN reg1 ) {
X . a
}

FOREACH ( Y IN reg2 ) {

Now after this if I do ctrl+space I will expect only Y should pop-up. But X and Y both are getting pop-up. How to restrict X to first FOREACH loop? out of first FOREACH loop X and its value should be erased. Please anyone suggest me how to implement this?

The related grammar rule is:

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]
;

Scope provider :

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

1 回答 1

1

您是否在作用域实现中设置了断点?您为语法定义了范围实现,attr但没有为varref语法定义范围实现。沿着这些思路添加一个实现就可以了。

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

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

于 2013-04-24T07:48:07.197 回答