I am using Sirius and Xtext to do a graphic-text two-way synchronization work, probably after I use Sirius to draw a graphic to generate Xtext text, and modifying the text will modify the graphic synchronously. When I draw with Sirius, the model will store a lot of necessary information, as shown below [enter image description here][1] I will get the XML likes this :
<siriusModel:ElementFactory>
<Elements> type="A" deviveName="A" logicalEntity="AbstractA"
<Elements> type="B" deviceName="B" logicalEntity="AbstractB"
</Elements>
</Elements>
</siriusModel:ElementFactory>
My xtext grammer is like this:
ElementFactory returns ElementFactory:
{ElementFactory}
'ElementFactory'
'{'
Elements+=Element*
'}';
Element returns Element:
{Element}
'{'
'[''type''='type=STRING']'
'[''deviceName''='deviceName=STRING']'
'[''logicalEntity''='logicalEntity=STRING']'
'}';
And my DSL looks like this:
ElementFactory{
Element{
[type="A"]
[deviceName="A"]
[logicalEntity="AbstractA"]
}
Element{
[type="B"]
[deviceName="B"]
[logicalEntity="AbstractB"]
}
}
but i don't want to show the [deviceName="A"] and [logicalEntity="AbstractA"] , I only want to this:
ElementFactory{
Element{
[type="A"]
}
Element{
[type="B"]
}
}
is there any way i can do it? Any help i would appreciate! thanks! [1]: https://i.sstatic.net/qh5Qy.png
Your problem is that you want your textual concrete syntax (Xtext grammar) to not represent your whole semantic model. As far as I know this is not really possible for Xtext: in general the whole file is the whole model. In Sirius you can more easily choose to not represent some of the semantic informations and its OK.
I would advise you to devise a "real, complete" abstract syntax for your language, then also create an Xtext-facing abstract syntax to use for the textual parts, and synchronize between the "real" model and the "made for text" one. I believe Eclipse OCL works like this as well with several metamodels with transformations in-between in order to both accomodate the Xtext technology and the OCL standard/API it is supposed to conform to.