我刚刚开始学习XTEXT,我可以看到自动编码的美好未来。 :)目前我正在研究七种语言的培训部分,我被困在MongoDb示例上。我正在关注该示例的描述,但我遇到DSL内部未解析类型的问题(当我尝试在'Artist'中定义'Album'或'Track'时,IDE显示“无法解析为类型”)
提前致谢
grammar org.xtext.example.mydsl.MongoBeans with org.eclipse.xtext.xbase.Xbase
generate mongoBeans "http://www.xtext.org/example/mydsl/MongoBeans"
MongoFile:
importSection=XImportSection?
elements+=AbstractElement*;
AbstractElement:
PackageDeclaration | MongoBean;
PackageDeclaration:
'package' name=QualifiedName '{'
elements+=AbstractElement*
'}';
MongoBean:
name=ValidID '{'
features+=AbstractFeature*
'}';
AbstractFeature:
MongoOperation | MongoProperty;
MongoProperty:
(type=JvmTypeReference | inlineType=MongoBean) (many?='*')? name=ValidID;
MongoOperation:
=>(returnType=JvmTypeReference name=ValidID '(')
(parameters+=FullJvmFormalParameter
(',' parameters+=FullJvmFormalParameter)*
)?
')'
body=XBlockExpression;
package org.musicdb {
// a mongo bean
Artist {
String name // single valued property
Album* album
Album* albums // array property
// an operation
Iterable<Track> getOeuvre() {
albums.map[track].flatten
}
}
// another mongo bean
Album {
String title
int year
// inline definition of a mongo bean
Track {
String title
int seconds
}* tracks
}
}