Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » sorting of grammar elements wrong after model modification(the elements in DSL have other sorting as before saving.)
sorting of grammar elements wrong after model modification [message #662173] Tue, 29 March 2011 15:38 Go to next message
goerkem is currently offline goerkemFriend
Messages: 20
Registered: October 2009
Junior Member
I parse my model and saves changed information this way:

ResourceSet rs = new XtextResourceSet();
XtextResource res = null;

try {
res = (XtextResource) rs.getResource(URI.createFileURI("myfile"), true);
}
catch(RuntimeException rte) {...}
...
res.save(null);

Afterthere the elements in my DSL have other sorting as before saving.

The grammar looks like:
Root : (header+=Header | footer+=Footer)*;
Header : A | B | C ;
A : 'A' name=ID;
B : 'B' name=ID;
C : D | E;
D : 'D' name=ID;
E : 'E' name=ID;
Footer : 'Footer' name=ID;

So before parsing i have written elements in such order:

D elementD
Footer footer
A elementA
B elementB

after parsing it becomes:

Footer footer
D elementD
A elementA
B elementB

If i change first line in grammar to
Root : (footer+=Footer | header+=Header)*;

I get order:

D elementD
A elementA
B elementB
Footer footer

Is there any possibility to keep order of dsl-elements after saving process as it is?
Re: sorting of grammar elements wrong after model modification [message #662202 is a reply to message #662173] Tue, 29 March 2011 17:26 Go to previous messageGo to next message
Alexander Nittka is currently offline Alexander NittkaFriend
Messages: 1193
Registered: July 2009
Senior Member
Hi,

I think the problem you are facing is described in the serialisation section of the Xtext documentation. With your grammar you don't give the model a chance to know the order of elements. Root has two list features header and footer, but the order within these lists can be reconstructed from the model but not the order of elements between two elements coming from different lists.

If you are free to define the grammar and the metamodel you can do the following:

Root: element+=Element*;
Element: Header|Footer;

Now Root has only one list and the order is kept. Of course, now you cannot select Headers and Footers directly. Instead you have to iterate over all elements selecting those of the correct type.

Alex
Re: sorting of grammar elements wrong after model modification [message #662348 is a reply to message #662202] Wed, 30 March 2011 10:23 Go to previous messageGo to next message
goerkem is currently offline goerkemFriend
Messages: 20
Registered: October 2009
Junior Member
No other way to keep order without changing grammar?
Re: sorting of grammar elements wrong after model modification [message #662353 is a reply to message #662348] Wed, 30 March 2011 10:52 Go to previous message
Alexander Nittka is currently offline Alexander NittkaFriend
Messages: 1193
Registered: July 2009
Senior Member
Hi,

usually serialisation uses the node model (basically the tree representation of the model file) for creating the output. However, if you make programmatic changes to the model, it can happen that the node model gets useless, so a complete serialisation (from the semantic model only) is done. And if there are no indicators for the position of an element in the semantic model...

The grammar looks strange to me anyway, as there is no semantic relation between headers and footers. I would expect something like

Root: elements+=Elements*;
Element: headers+=Header* footer=Footer;
...

if this is the intended relation between headers and footers

Alex
Previous Topic:Problem with unordered List and cardinality
Next Topic:NullPointerException in DefaultResourceDescriptionManager
Goto Forum:
  


Current Time: Tue Apr 30 05:17:35 GMT 2024

Powered by FUDForum. Page generated in 0.03540 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top