[Solved] Referencing to two separate types [message #1780268] |
Fri, 19 January 2018 12:56 ![Go to next message Go to next message](theme/Solstice/images/down.png) |
Ray Kerstens![Friend of Eclipse Friend](/donate/web-api/friends_decorator.php?email=r.j.c.m.kerstens%40student.tue.nl) Messages: 8 Registered: January 2018 |
Junior Member |
|
|
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 08:28] Report message to a moderator
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03742 seconds