如果我有一个像下面这样的 Xtext 语法:
grammar org.xtext.example.mydsl.ServerGeneratorLanguage with org.eclipse.xtext.common.Terminals
generate serverGeneratorLanguage "http://www.xtext.org/example/mydsl/ServerGeneratorLanguage"
Model:
(types+=Type)*;
Type:
Server | DomainModel;
Server:
"SERVER" name=ID "{"
"CONFIG" "{"
(Configs+=Config)*
"}"
"}";
Config:
rootConfig | hostNameConfig | portConfig | logConfig | sqldbConfig | resourceConfig;
rootConfig:
"ROOTDIR" "=" name=ID;
hostNameConfig:
"HOSTNAME" "=" name=ID;
portConfig:
"PORT" "=" name=ID;
logConfig:
"LOG" "=" name=ID;
sqldbConfig:
"SQLDB" "=" name=ID;
resourceConfig:
"RESOURCE" "=" name=ID;
DomainModel:
"DOMAINMODEL" name=ID "{"
"ENTITYS" "{"
(Entitys+=Entity)*
"}"
"ENTITY_RELATIONSHIP" "{"
(Relationships+=Relationship)*
"}"
"}";
Entity:
name=ID "{"
(Attributes+=Attribute)*
"}";
Attribute:
StringAttribute | NumberAttribute | ImageAttribute;
StringAttribute:
"STRING" name=ID;
NumberAttribute:
"NUMBER" name=ID;
ImageAttribute:
"IMAGE" name=ID;
QualifiedName:
ID ('.' ID)*;
Relationship:
name=[Attribute|QualifiedName] "->" refName=[Attribute|QualifiedName];
如何name-ID
从比 Server 更高的级别访问每个 Config 对象的部分。让我解释:
Server.configs.eClass.name
我想通过从AS WELL AS收集数据来生成代码DomainModel.blahblah.eClass.name
。我假设我需要从 Type 访问它,但我似乎无法在 Xtend 中访问它。
从服务器我可以访问所有组件Server.configs.eClass.name.
感谢您的帮助。