0
votes

In my dsl I was trying the following:

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]
    ']'
;

My problem is on the step. I want only the ingredients I've declared on the Recipe to appear. For example if I do this:

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

    ]
}

Below cut I only want fish and meat to appear as options.

I've read about cross-references but I can't get it to work while using an enum to limit user input.

1

1 Answers

0
votes

Xtext can reference things with names only. you dont have names, you have ingredient_name. also names have to be Strings by default. => You have to implement IQualifiedNameProvider (usually a subclass of DefaultDeclarativeQualifiedNameProvider`) https://www.dietrich-it.de/xtext/2011/07/16/iqualifiednameproviders-in-xtext-2-0.html