Xtext交叉引用无法正常工作



在我的dsl中,我尝试了以下操作:

grammar org.xtext.example.mydsl.Recipe with org.eclipse.xtext.common.Terminals
generate recipe "http://www.xtext.org/example/mydsl/Recipe"

Model:
recipe=Recipe;

enum Ingredients:
Meat | Fish | Rice
;
enum Steps_Type:
Cut | Boil | Prepare
;
Recipe:
'Recipe'
'{'
ingredient+=Ingredient+
step+=Step+
'}'
;
Ingredient:
'ingredient' ingredient_name=Ingredients quantity=INT ('kg' | 'g')
;
Step:
'['
step=Steps_Type
ingredient=[Ingredient]
']'
;

我的问题出在台阶上。我只想让我在食谱上声明的成分出现。例如,如果我这样做:

Recipe {
ingredient Fish 1 kg
ingredient Meat 2kg
[
Cut
]
}

在下面的切口,我只想让鱼和肉作为选项出现。

我读过关于交叉引用的文章,但在使用枚举来限制用户输入时,我无法使其发挥作用。

Xtext只能引用具有names的内容。你没有name,你有ingredient_name。默认情况下,名称也必须是字符串。=>您必须实现IQualifiedNameProvider(通常是DefaultDeclarativeQualifiedNameProvider的子类`(https://www.dietrich-it.de/xtext/2011/07/16/iqualifiednameproviders-in-xtext-2-0.html

最新更新