On-the-fly declaration in cross-reference [message #1840806] |
Sun, 25 April 2021 06:33  |
Eclipse User |
|
|
|
I am trying to create a grammar for an existing metamodel. Here is a relevant part of the grammar:
Ingredient: amount=INT name=EString ;
Container: 'container' name=EString ;
ContainmentRelation: ingredient=[Ingredient] '->' container=[Container] ;
I would want to be able to declare Containers and then write ContainmentRelations which describe Ingredients being contained inside the Containers. But I do not want to have to predeclare my Ingredients and then write the ContainmentRelations, I would like to be able to simply write a ContainmentRelation where on the left side of the arrow (->) I could declare a new Ingredient.
Here is an example; instead of this:
4 'carrot' // this is an ingredient
2 'potato' // this is another ingredient
container 'pot' // this is a container
// now the containment relation:
carrot -> pot
potato -> pot
I would want to be able to do this:
container 'pot'
4 'carrot' -> pot
2 'potato' -> pot
----
I naturally tried to change the ingredient=[Ingredient] cross reference to simply Ingredient, but understandably I get Cannot add supertype 'ContainmentRelation' to sealed type 'Ingredient'.
Do I need to change my metamodel? I suppose it would work if I added another relation between Ingredient and ContainmentRelation that would be a composition but this does not really make sense since the Ingredient should not be 'owned' by the ContainmentRelation but by some larger wrapping object to all thes called Recipe (not present in my examples for simplicity).
[Updated on: Sun, 25 April 2021 11:53] by Moderator
|
|
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03774 seconds