Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Old vs new serializer
Old vs new serializer [message #1116499] Wed, 25 September 2013 14:26 Go to next message
Fabian G. is currently offline Fabian G.
Messages: 48
Registered: May 2010
Location: Namur (Belgium)
Member
Hi,

I'm currently using the old serializer to save a dsl model after having applied some transformations over it. It's working except that:

* the newly serialized model elements are present in the model in a different order
* some elements are printed on the same line as their predecessors (couldn't see what was different in my grammar)

I'm wondering if the new serializer could solve my problems or if I had to manage that differently.

If yes, I'm wondering how can I use the new serializer. For the old one, I extended the org.eclipse.xtext.parsetree.reconstr.Serializer, retrieve it by the IGlobalServiceProvider and call the serialize() method that gave me back the serialized string that I passed to an EclipseResourceFileSystemAccess2. How can I actually use the new one (couldn't find the info in the documentation).

Thanks in advance,
Cheers,

Fabian
Re: Old vs new serializer [message #1116500 is a reply to message #1116499] Wed, 25 September 2013 14:28 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian Dietrich
Messages: 6388
Registered: July 2009
Senior Member
Hi,

you have to change the workflow to create the new serializer

replace the parsetreeconstructorfragment with serializer.SerializerFragment
and ask the serviceprovider for a org.eclipse.xtext.serializer.ISerializer
Re: Old vs new serializer [message #1116518 is a reply to message #1116500] Wed, 25 September 2013 14:51 Go to previous messageGo to next message
Fabian G. is currently offline Fabian G.
Messages: 48
Registered: May 2010
Location: Namur (Belgium)
Member
Thanks for your quick answer Christian, I saw that in the workflow.

The problem is that I have multiple serializers for different languages called from another plugin (please see this thread for the complete simplified explanation http://www.eclipse.org/forums/index.php/m/1105973/#msg_1105973). In brief, I have to extend the serializer, but I get a warning on access restriction. How can I easily extend the serializer so that I can retrieve it from the other plugin ? Maybe I can just ignore the warnings.

thanks,
Fabian
Re: Old vs new serializer [message #1116526 is a reply to message #1116518] Wed, 25 September 2013 15:03 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian Dietrich
Messages: 6388
Registered: July 2009
Senior Member
Hi,

i have so idea what you are doing. but restricted api warning say: be careful the api can change.
Re: Old vs new serializer [message #1117220 is a reply to message #1116526] Thu, 26 September 2013 08:01 Go to previous messageGo to next message
Fabian G. is currently offline Fabian G.
Messages: 48
Registered: May 2010
Location: Namur (Belgium)
Member
thanks, the new serializer is actually easier to use and I found another way than extending it for my purpose.

the order is almost respected now, but I still have a couple of lines that are joined and one block of comment is ignored (any idea?).

Any idea to have the model elements printed in the same order and having them on different lines (separated in the source model and grammar rules are the same "kind" as the other ones)?

thanks again!

[Updated on: Thu, 26 September 2013 08:45]

Report message to a moderator

Re: Old vs new serializer [message #1117294 is a reply to message #1117220] Thu, 26 September 2013 09:30 Go to previous messageGo to next message
Moritz Eysholdt is currently offline Moritz Eysholdt
Messages: 142
Registered: July 2009
Location: Kiel, Germany
Senior Member
The serializer respects your formatter configuration. Depending on the options you pass to the serializer, it'll format all whitespace or just the whitespace were no existing whitespace (because the model was changed programmatically) can be found.

If other unexpected things happen, could you post small examples that illustrate what's happening? Then we can see if it's intentional or a bug.

regards,
Moritz
Re: Old vs new serializer [message #1117350 is a reply to message #1117294] Thu, 26 September 2013 10:47 Go to previous messageGo to next message
Fabian G. is currently offline Fabian G.
Messages: 48
Registered: May 2010
Location: Namur (Belgium)
Member
Hi Moritz,

I did not touch to the formatter. It seems the serializer follows the order defined in the grammar and if two dsl elements are interchanged, the serialization produces a strange behaviour. An example grammar (did not test with this example, but have the same pattern in my language with a bigger abstract rule) :
ASampleRule :
  (sub1+=SubRule1 | sub2+=SubRule2)*;

SubRule1 :
  'subrule1' name=ID ';';

SubRule2 :
  'subrule2' name=ID ';';

The model:
subrule1 id1;
// a comment
subrule2 id2;

will be serialized correctly, but the model:
// a comment
subrule2 id2;
// a comment
subrule1 id1;

will produce
subrule2 id2; subrule1 id1;

In other words, when a couple of rules can be present in multiple instances and interchanged, it seems the serializer does not produce the expected result. For the order, this is no big deal, but the comments defined upper and in between are lost which is more problematic.

Thanks for your help,
Regards,
Fabian

[Updated on: Thu, 26 September 2013 10:58]

Report message to a moderator

Re: Old vs new serializer [message #1117355 is a reply to message #1117350] Thu, 26 September 2013 10:54 Go to previous messageGo to next message
Uli Merkel is currently offline Uli Merkel
Messages: 125
Registered: June 2013
Senior Member
I'm just experimenting with XTEXT/XTEND,but the following grammar may help:

Model: modules+=(Module)+;
Module: (Module1 | Module2);
Module1: 'module1' name=ID arg1=STRING arg2=STRING;
Module2: 'module2' name=ID arg1=STRING arg1a=STRING?;

My Generator uses:
«FOR Module modul : sm.modules»
«switch modul {
Module1:{genModule1(modul as Module1)}
Module2:{genModule2(modul)}

«ENDFOR»
Re: Old vs new serializer [message #1117369 is a reply to message #1117355] Thu, 26 September 2013 11:12 Go to previous messageGo to next message
Fabian G. is currently offline Fabian G.
Messages: 48
Registered: May 2010
Location: Namur (Belgium)
Member
That's how I was doing earlier, I defined my own serializer.

But the idea is to avoid doing it because Xtext generates one for me that evolves with the language. Otherwise, at any grammar change, the serializer must be manually updated which is far from a good idea, especially with the grammar I have (pretty big).
Re: Old vs new serializer [message #1117383 is a reply to message #1117369] Thu, 26 September 2013 11:33 Go to previous messageGo to next message
Moritz Eysholdt is currently offline Moritz Eysholdt
Messages: 142
Registered: July 2009
Location: Kiel, Germany
Senior Member
Fabian, could you file a bugzilla ticket for your scenario? It might also help to structure your model as Uli suggested (use one containment ref plus inheritance instead of using two containment refs) because then the order is stored in the EMF model and doesn't have to be reconstructed from the node model.

Writing your own templates usually gets even more complicated once you want to preserve formatting and comments.

Re: Old vs new serializer [message #1117464 is a reply to message #1117383] Thu, 26 September 2013 13:26 Go to previous messageGo to next message
Fabian G. is currently offline Fabian G.
Messages: 48
Registered: May 2010
Location: Namur (Belgium)
Member
filed the bug here.
I'll test by adapting my grammar with the proposed structure and come back here asap.

Thanks again,
cheers,
F.
Re: Old vs new serializer [message #1117512 is a reply to message #1117464] Thu, 26 September 2013 14:25 Go to previous message
Fabian G. is currently offline Fabian G.
Messages: 48
Registered: May 2010
Location: Namur (Belgium)
Member
Tested after reformating the rules, serializer behaves as expected.
Moreover, as a side effect, I could remove a quick-dirty-fix for the scope provider that was not working correctly for one type of reference.

So, if you have the same problem, one advice, reformat the rule as suggested by Uli.
Previous Topic:Static in Xtend
Next Topic:Formatter adds line breaks
Goto Forum:
  


Current Time: Sat Oct 25 03:39:38 GMT 2014

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

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