我有一个简单的语言,有类似枚举的东西。如何获得交叉引用的EnumEntry的工作解决方案。也可以通过EnumEntity过滤EnumEntry ...
MyDsl.xtext
grammar org.xtext.example.mydsl.MyDsl with
org.eclipse.xtext.common.Terminals
generate myDsl "http://www.xtext.org/example/mydsl/MyDsl"
Model:
entity_node = Entity | EnumEntity;
Entity:
type = ('my_entity') ':' name = ID '{'
(parts += EntityPart)*
'}';
EnumEntity:
type = ('my_enum') ':' name = ID '{'
//entry = EnumEntry (',' entrys+= EnumEntry)* Fixed after Christian comment
entrys+= EnumEntry (',' entrys+= EnumEntry)*
'}';
EnumEntry:
name = ID;
EnumUsage:
/* What should I do here? */
enumEntity = [EnumEntity]'.'entry = [EnumEntry];
EntityPart:
EnumUsage ';';
my_enum_entity.mydsl
my_enum:my_enum_entity
{
my_enum_entry_1,
my_enum_entry_2,
my_enum_entry_3
}
my_pretty_entity.mydsl
my_entity:my_pretty_entity
{
my_enum_entity.my_enum_entry_2;
}
答案 0 :(得分:1)
您没有自定义scopeprovider,或者您只是错过了发布代码?
id期待类似
的内容class MyDslScopeProvider extends AbstractMyDslScopeProvider {
override getScope(EObject context, EReference reference) {
if (reference == MyDslPackage.Literals.ENUM_USAGE__ENUM_ENTRY) {
if (context instanceof EnumUsage) {
return Scopes.scopeFor(context.enumEntity.entrys)
}
}
super.getScope(context, reference)
}
}
如果你不想适应范围,请调整语法,如
EnumUsage: entry = [EnumEntry|FQN];
FQN: ID ("." ID)*;