[Solved] Referencing to two separate types [message #1780268] |
Fri, 19 January 2018 07:56  |
Eclipse User |
|
|
|
Hi all,
I'm working on my first DSL and I'm running into a problem. The goal is that ultimately one is able to define the following:
Supermarket
HealthyProductTypes
HealtyProductType Fruit
HealthyProductType Vegetable
UnHealthyProductTypes
UnHealtyProductType Soda
UnHealthyProductType Snack
Products
Product Coke Type Soda
Product Apple Type Fruit
Product Crisps Type Snack
The grammar I have for now is:
Model:
supermarkets += Supermarket
;
Supermarket:
"Supermarket"
"HealthyProductTypes" healthyproducttypes += HealthyProductType+
"UnHealthyProductTypes" uhealthyproducttypes += UnHealthyProductType+
"Products" products += Product+
;
HealthyProductType:
"HealthyProductType" name=ID
;
UnHealthyProductType:
"UnHealthyProductType" name=ID
;
Product:
"Product" name=ID
"Type"
type=[HealthyProductType] | [UnHealthyProductType]
;
That final part (type=[HealthyProductType] | [UnHealthyProductType]) yields the error "A rule's name has to be unique". I also tried doing it in the following manner
Product:
"Product" name=ID
"Type"
type= HealthyReference | UnhealthyReference
;
HealthyReference :
reference = [HealthyProductType]
;
UnhealthyReference:
reference = [UnHealthyProductType]
But that yields an error when generating "Decision can match input such as "RULE_ID" using multiple alternatives: 1, 2"
What would be the way to get the functionality I want?
Edit:
Christian DietrichFriend Posted the functionality I wanted. For future reference, this is the resulting grammar:
Model:
supermarkets += Supermarket
;
Supermarket:
"Supermarket"
"HealthyProductTypes" healthyproducttypes += HealthyProductType+
"UnHealthyProductTypes" uhealthyproducttypes += UnHealthyProductType+
"Products" products += Product+
;
HealthyProductType:
"HealthyProductType" name=ID
;
UnHealthyProductType:
"UnHealthyProductType" name=ID
;
Product:
"Product" name=ID
"Type"
type= [ProductType]
;
ProductType:
HealthyProductType | UnHealthyProductType
;
Kind regards,
Ray
[Updated on: Mon, 22 January 2018 03:28] by Moderator
|
|
|
|
|
Re: Referencing to two separate types [message #1780402 is a reply to message #1780304] |
Mon, 22 January 2018 03:32  |
Eclipse User |
|
|
|
Christian Dietrich wrote on Fri, 19 January 2018 17:17this is not possible you need to introduce a common supertype like
ProductType: HealthyProductType | UnHealthyProductType;
and then ref=[ProductType]
Thanks, this indeed does the trick. I edited my main post to include the solution and marked the topic as solved.
Axel Guckelsberger wrote on Fri, 19 January 2018 17:21Maybe also consider a more concise syntax like:
Products
Soda Coke
Fruit Apple
Snack Crisps
or
Products: Coke (Soda), Apple (Fruit), Crisps (Snack)
Noted, I will surely edit that in a later version. Thank you for your input.
|
|
|
Powered by
FUDForum. Page generated in 0.05352 seconds