How to define Xtext grammar for a strange scenario [message #1793243] |
Thu, 02 August 2018 06:36 |
mind calm Messages: 57 Registered: July 2017 |
Member |
|
|
Hi,
I have a model with two types, Array and Element, the Array contains elements.
I want the dsl allow below style:
array arr1 {
elements {
ele1,
element ele3 {
price 10
}
}
}
element ele1 {
price 8
}
It means in elements, Element entity and Element reference can be coexist. Is it possible? If it is possible, how to define the grammar?
Best regards!
by Keep Mind Calm
[Updated on: Thu, 02 August 2018 07:11] Report message to a moderator
|
|
|
|
Re: How to define Xtext grammar for a strange scenario [message #1793252 is a reply to message #1793245] |
Thu, 02 August 2018 07:53 |
mind calm Messages: 57 Registered: July 2017 |
Member |
|
|
Hi, Christian
Sorry for i did not describe it clearly. I post my grammar and model below:
grammar org.mydsl.MyDsl with org.eclipse.xtext.common.Terminals
import "http://www.eclipse.org/emf/2002/Ecore" as ecore
generate myDsl "http://www.mydsl.org/MyDsl"
Model:
greetings+=AbstractElement*;
AbstractElement:
Array | Element
;
Array:
'array' name=ID '{'
'elements' '{' (elements+=[Element|EString] ("," elements+=[Element|EString])*)? '}'
'}';
Element:
'element' name=ID '{'
'price' price=EInt
'}'
;
EInt returns ecore::EInt:
'-'? INT;
EString returns ecore::EString:
STRING | ID;
array arr1 {
elements {
ele1,
element ele2 {
price 2
}
}
}
element ele1 {
price 5
}
There will have errors at line "element ele2 {" in Xtext editor.
From your reply, do you mean we define a type ElementReference? but i just want use the attribute name as reference of Element, is it possible?
Best regards!
by Keep Mind Calm
[Updated on: Thu, 02 August 2018 07:55] Report message to a moderator
|
|
|
|
Powered by
FUDForum. Page generated in 0.03688 seconds