Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » XText ValueConverter And Generated Editor Issue
XText ValueConverter And Generated Editor Issue [message #1049266] Thu, 25 April 2013 15:44 Go to next message
Ronan B is currently offline Ronan BFriend
Messages: 273
Registered: July 2009
Senior Member
Hi,
I have written an IValueConverter which allows me to generate RegExs without the default XText backslash escaping. This seems to work fine as my ATL generator runs nicely. However, when I open the generated file using the XText generated editor I see red marks all over the RegExs where backslashes are. Did I miss something?

Perhaps it has something todo with the toValue method in IValueConverter? I don't know what that does. I placed custom backslash replace code in the toString method to handle a special case at serialization time.

My code is as follows:

public class RegExConverter extends DefaultTerminalConverters {
@ValueConverter(rule = "RegEx")
public IValueConverter<String> RegEx() {
return new IValueConverter<String>() {

@Override
//TODO:Not sure what this method is really doing
public String toValue(String string, INode node) throws ValueConverterException {
if (string == null)
return null;
else
//return this.toString(string);
return string;
}

@Override
public String toString(String value) throws ValueConverterException {
if (value == null)
return null;
else
//YANG/XSD gets upset with double backslash so we replace it with triple
return '"' + value.replace("\\\\", "\\\\\\") + '"';
}

};
}

Thanks,
Ronan
Re: XText ValueConverter And Generated Editor Issue [message #1049730 is a reply to message #1049266] Fri, 26 April 2013 07:49 Go to previous messageGo to next message
Alexander Nittka is currently offline Alexander NittkaFriend
Messages: 1193
Registered: July 2009
Senior Member
Hi,

the purpose of the value converter is to transform the model file text content to the internal data representation *and back*. Hence the two methods toValue and toString.

As for the errors shown in the editor, I guess you did not adapt the STRING terminal rule. It simply does not cover the input you want. (A value converter does not help for that)

Alex
Re: XText ValueConverter And Generated Editor Issue [message #1049743 is a reply to message #1049730] Fri, 26 April 2013 08:08 Go to previous message
Ronan B is currently offline Ronan BFriend
Messages: 273
Registered: July 2009
Senior Member
Aha!
Great that makes lots of sense. I forgot to fix the terminals.
Thanks!
Ronan
Previous Topic:Help needed in Xtext
Next Topic:ATL Transformation between validation and generation - how to insert
Goto Forum:
  


Current Time: Wed Dec 07 15:09:18 GMT 2016

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

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