Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Serializing an unordered group?
Serializing an unordered group? [message #1689469] Mon, 23 March 2015 16:37 Go to next message
Stephan Herrmann is currently offline Stephan HerrmannFriend
Messages: 1830
Registered: July 2009
Senior Member
Hi,

I have a grammar with a big unordered group, some elements of which are 0..1 and the others are 0..n, s.t., like:
( elem1=Rule1?
 & elem2+=Rule2*
 & elem3+=Rule3*
 & elem4=Rule4?
 ...)


Next I have a model that populates some of the elements of this group.

Then I try to add more elements via a semantic modification (xtextEditor.getDocument().modify(..)).

The effect I'm seeing: all new elements for the unordered group are appended to the end of the existing content. This, however, violates the constraint of the unordered group:
Quote:
Elements with a cardinality of * or + have to appear continuously without interruption


Does the serializer have a hook where I can influence serialization as to generate a valid model in this situation?

thanks
Stephan
Re: Serializing an unordered group? [message #1689476 is a reply to message #1689469] Mon, 23 March 2015 16:53 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13882
Registered: July 2009
Senior Member
Hi can you please file a which serializer do you use?

Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Serializing an unordered group? [message #1689486 is a reply to message #1689476] Mon, 23 March 2015 17:33 Go to previous messageGo to next message
Stephan Herrmann is currently offline Stephan HerrmannFriend
Messages: 1830
Registered: July 2009
Senior Member
Christian Dietrich wrote on Mon, 23 March 2015 17:53
Hi can you please file a which serializer do you use?


I'm using the default implementation generated by this entry in the workflow:
    		fragment = serializer.SerializerFragment auto-inject {
    			generateStub = false
    		}


Meanwhile I found that the simple case as posted previously actually works, the thing that breaks it was simplified away for the post, it looks s.t. like this:

('kw1'
	(('kwa' elema+=[Elema])
	| ('kwb' elemb+=[Elemb])
	)
)*


This snippet then was one member of my unordered group. If I pull this construct out of the group the remaining entries seem to be correctly grouped during serialization.

I'm willing to rewrite my grammar, if that helps the serializer, but so far I found no variant that would support one group of 'kw1' 'kwa' entries plus a group of 'kw1' 'kwb' entries. Factorization seems to confuse the serializer ... (and I don't want to create keywords with spaces like 'kw1 kwa' Smile )

thanks,
Stephan
Re: Serializing an unordered group? [message #1689538 is a reply to message #1689486] Mon, 23 March 2015 20:22 Go to previous messageGo to next message
Stephan Herrmann is currently offline Stephan HerrmannFriend
Messages: 1830
Registered: July 2009
Senior Member
Twenty or so grammars later I still don't know which factor exactly makes the difference. It's not the double keywords, it's not the fact that some group elements are separate rules while others are inline.

Maybe when pulling the two special elements out of the unordered group I just got lucky in my experiments, but that's the only way I could get the serializer to work, i.e., produce valid models.

This implies, that I will have to force an order in my grammar, where previous versions let users choose the order.

BTW: In successful attempts the sub-list that I was adding to was always pulled to the end of the unordered group (also end of the document), so maybe it's just not possible to add to two sub-lists within the same unordered group at the same time ...

Any hints on how to adapt the serializer in these regards appreciated,

Stephan
Re: Serializing an unordered group? [message #1689566 is a reply to message #1689538] Mon, 23 March 2015 21:34 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7096
Registered: July 2009
Senior Member
Hi Stephan

I have tried using unordered groups a couple of times to improve a
grammar written before they existed. However I have reverted each time.

I suggest that you abandon them and just use a bunch--of-adjectives
collection so that any order is permitted.

Unfortunately you are then obliged to use validation rules to impose
restrictions on multiplicity.

Regards

Ed Willink


On 23/03/2015 20:22, Stephan Herrmann wrote:
> Twenty or so grammars later I still don't know which factor exactly
> makes the difference. It's not the double keywords, it's not the fact
> that some group elements are separate rules while others are inline.
>
> Maybe when pulling the two special elements out of the unordered group
> I just got lucky in my experiments, but that's the only way I could
> get the serializer to work, i.e., produce valid models.
>
> This implies, that I will have to force an order in my grammar, where
> previous versions let users choose the order.
>
> BTW: In successful attempts the sub-list that I was adding to was
> always pulled to the end of the unordered group (also end of the
> document), so maybe it's just not possible to add to two sub-lists
> within the same unordered group at the same time ...
>
> Any hints on how to adapt the serializer in these regards appreciated,
>
> Stephan
Re: Serializing an unordered group? [message #1689570 is a reply to message #1689566] Mon, 23 March 2015 21:37 Go to previous message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7096
Registered: July 2009
Senior Member
On 23/03/2015 21:34, Ed Willink wrote:
> I have tried using unordered groups a couple of times to improve a
> grammar written before they existed. However I have reverted each time.
Most recently https://bugs.eclipse.org/bugs/show_bug.cgi?id=427020.

Regards

Ed Willink
Previous Topic:Extending existing files with Xtend
Next Topic:How to add a code segment into the current editor via popup menu?
Goto Forum:
  


Current Time: Wed Apr 14 09:11:13 GMT 2021

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

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

Back to the top