Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » STRING serialization not producing quotes if no whitespace
STRING serialization not producing quotes if no whitespace [message #885083] Tue, 12 June 2012 12:40 Go to next message
Thomas Altenburger is currently offline Thomas AltenburgerFriend
Messages: 3
Registered: June 2012
Junior Member
Hello,

I would like to serialize ecore files conforming to an xtext grammar. I bound the ecore EString type to the STRING terminal (not STRING | ID, as automatically generated when deriving ecore with xtext) because I want strings to be single/double quoted.

The grammar works as expected with the plugin. The problem is that when I tried to serialize an xmi resource through my grammar, EString are not quoted if they do not contain whitespaces (as if they were serialized to ID, despite my grammar).

Any hint on this? Thanks.

[Updated on: Tue, 12 June 2012 12:42]

Report message to a moderator

Re: STRING serialization not producing quotes if no whitespace [message #885291 is a reply to message #885083] Tue, 12 June 2012 18:53 Go to previous messageGo to next message
Christian Dietrich is currently online Christian DietrichFriend
Messages: 13628
Registered: July 2009
Senior Member
Hi,

hmm can you share you grammar? and maybe a unit test?
if org.eclipse.xtext.conversion.impl.STRINGValueConverter is used the quotes seem to be added always.

~Christian


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: STRING serialization not producing quotes if no whitespace [message #885684 is a reply to message #885291] Wed, 13 June 2012 12:40 Go to previous messageGo to next message
Thomas Altenburger is currently offline Thomas AltenburgerFriend
Messages: 3
Registered: June 2012
Junior Member
Hi Christian,

After some more research, I found that Xtext calls org.eclipse.xtext.common.services.Ecore2XtextTerminalConverters when it encounters an EString. And it effectively tries to match the ID_PATTERN before trying to make it fit into a STRING (see Ecore2XtextTerminalConverters). Quite logical.

The problem is the following rule I would like to work when serializing:
EString returns ecore::EString:
	STRING; // instead of ID | STRING


But it seems that xtext does not allow ecore data type to be "redefined".
When serializing ecore data types, xtext simply ignore such rules by considering ecore data types as terminals. Making serialized ecore to not conform to the grammar.

Any way to override Ecore2XtextTerminalConverters?

[Updated on: Wed, 13 June 2012 12:43]

Report message to a moderator

Re: STRING serialization not producing quotes if no whitespace [message #885702 is a reply to message #885684] Wed, 13 June 2012 12:58 Go to previous messageGo to next message
Christian Dietrich is currently online Christian DietrichFriend
Messages: 13628
Registered: July 2009
Senior Member
Hi you should be able to exchange it with Google guice

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: STRING serialization not producing quotes if no whitespace [message #885710 is a reply to message #885702] Wed, 13 June 2012 13:16 Go to previous message
Thomas Altenburger is currently offline Thomas AltenburgerFriend
Messages: 3
Registered: June 2012
Junior Member
Done it!

Here is the solution in case anyone run into a similar situation.

I extended Ecore2XtextTerminalConverters to always convert ecore::EString to xtext::STRING:
package your.package;

import org.eclipse.xtext.common.services.Ecore2XtextTerminalConverters;
import org.eclipse.xtext.conversion.IValueConverter;
import org.eclipse.xtext.conversion.ValueConverter;
import org.eclipse.xtext.conversion.impl.AbstractNullSafeConverter;
import org.eclipse.xtext.nodemodel.INode;

public class EString2XtextConverter extends Ecore2XtextTerminalConverters {
	
	@ValueConverter(rule = "EString")
	public IValueConverter<String> EString() {
		return new AbstractNullSafeConverter<String>() {
			@Override
			protected String internalToValue(String string, INode node) {
				return STRING().toValue(string, node);
			}

			@Override
			protected String internalToString(String value) {
				return STRING().toString(value);
			}
		};
	}
}


And registered it in the RuntimeModule:

public class YourDslRuntimeModule extends your.package.AbstractYourDslRuntimeModule {
	
	@Override
	public Class<? extends IValueConverterService> bindIValueConverterService() {
		return EString2XtextConverter.class;
	}
	
}


Thx Christian.
Previous Topic:XTend 2.2.1 installation broken? (NPE at BuilderParticipant.java:184)
Next Topic:Trying to include templates.xml in xtext plugin
Goto Forum:
  


Current Time: Tue Oct 20 12:45:58 GMT 2020

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

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

Back to the top