如何配置 Xtext mwe.Reader 以填充槽中的根元素
我将 Xtext 2.0 与 MWE 1 和 XPand 一起使用,但我猜 MWE 2 和 XTend 的问题完全相同。
我的 Xtext 语法看起来像这样(摘录):
grammer org.test.Test with org.eclipse.xtext.common.Terminals
generate test "http://www.test.org/test/Test
Model :
"COMMON STUFF"
"{"
(formatterDefs+=FormatterDef)*
"}"
...
FormatterDef : "Formatter" name=ID ":" formatter=STRING;
当我使用此 mwe 定义时(摘录):
<component class="org.eclipse.xtext.mwe.Reader" path="${project.src.directory}/xtext/model/" >
<register class="org.test.TestStandaloneSetup"/>
<load slot='formatterDefs' type='FormatterDef'/>
</component>
<component class="org.eclipse.xpand2.Generator">
<metaModel class="org.eclipse.xtend.typesystem.emf.EmfRegistryMetaModel"/>
<expand value="templates::Formatter::formatterTxt FOREACH formatterDefs"/>
</component>
因此槽 formatterDefs
填充了所有 FormaterDef
,然后将其用于模板,并且每个想法都工作正常。
但是我有一些模板需要模型根元素,在语法中名为 Model
。所以我尝试使用
<load slot='formatterDefs' type='FormatterDef'/>
and
<expand value="templates::Main::main FOREACH model"/>
来代替。
但后来我收到这个警告:
org.eclipse.xtext.mwe.SlotEntry - 找不到任何“Model”类型的导出元素 ->插槽“模型”为空。
并且该插槽包含一个空列表。
所以我的问题是:我需要做什么,才能将根模型
放入我的模板中?
I am using Xtext 2.0 with MWE 1 and XPand, but I guess the Problem for MWE 2 and XTend is exactly the same.
My Xtext grammer looks like this (excerpt):
grammer org.test.Test with org.eclipse.xtext.common.Terminals
generate test "http://www.test.org/test/Test
Model :
"COMMON STUFF"
"{"
(formatterDefs+=FormatterDef)*
"}"
...
FormatterDef : "Formatter" name=ID ":" formatter=STRING;
When I use this mwe definiton (excerpt):
<component class="org.eclipse.xtext.mwe.Reader" path="${project.src.directory}/xtext/model/" >
<register class="org.test.TestStandaloneSetup"/>
<load slot='formatterDefs' type='FormatterDef'/>
</component>
<component class="org.eclipse.xpand2.Generator">
<metaModel class="org.eclipse.xtend.typesystem.emf.EmfRegistryMetaModel"/>
<expand value="templates::Formatter::formatterTxt FOREACH formatterDefs"/>
</component>
So the slot formatterDefs
is filled with all FormaterDef
, and then this is used for the template, and every think works fine.
But I have some templates that requires the model root element, named Model
in the grammar. So I tryed to use
<load slot='formatterDefs' type='FormatterDef'/>
and
<expand value="templates::Main::main FOREACH model"/>
instead.
But then I get this warning:
org.eclipse.xtext.mwe.SlotEntry - Could not find any exported element of type 'Model' -> Slot 'model' is empty.
And the slot contains an empty list.
So my Question is: what do I need to do, to get the root Model
into my templates?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我的意思是
I meant something like
您可以自定义 IQualifiedNameProvider 来为模型命名。
~克里斯蒂安
you could customize the IQualifiedNameProvider to give the Model a name.
~Christian
最好的方法可能是在规则的开头插入文本
{Model}
以确保创建。Probably the best way is inserting the text
{Model}
just at the beginning of the rule, to ensure the creation.解决方案是向模型的语法定义添加 ID。
据我了解,之前没有现有的 Model 元素,因此在添加 ID 后,必须创建 Model 元素以包含 Id。
怎么可能有更好的解决方案 - 一旦发布我就会接受。
A solution was to add an ID to the Grammer Definiton of the Model.
I understand that there was no existing Model element before, so after adding the ID the Model element must be created to contain the Id.
How ever may there is a better solution - I will accept it, as soon as it is posted.