Skip to main content



      Home
Home » Modeling » TMF (Xtext) » XText ValueConverter And Generated Editor Issue
XText ValueConverter And Generated Editor Issue [message #1049266] Thu, 25 April 2013 11:44 Go to next message
Eclipse UserFriend
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 03:49 Go to previous messageGo to next message
Eclipse UserFriend
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 04:08 Go to previous message
Eclipse UserFriend
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: Fri Jul 04 14:09:15 EDT 2025

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

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

Back to the top