Unable to incorporate default IValueConverters [message #716844] |
Thu, 18 August 2011 15:03 |
|
Hi!
Having a blast playing with XText, but I've hit a brick wall I can't seem to surmount. I created a custom IValueConverter, and have it working (please see SOURCE below). However, the default IValueConverters do not seem to be working. For instance, I get parse errors in my generated editor for the ID rule - the only way to bypass the parse error is no prepend ID instances with '^' (please see Example below). Does anyone see my mistake?
Example
For this rule:
Define:
DefineKeyword
name = ID
value = (ID | STRING)
;
the following syntax results in an error:
yet this syntax parses successfully:
SOURCE
Bound my custom IValueConverterService implementation:
public class TplXRuntimeModule extends com.exoanalytic.seas.tplx.AbstractTplXRuntimeModule {
@Override
public Class<? extends IValueConverterService> bindIValueConverterService() {
return TplXValueConverterService.class;
}
}
Extended DefaultTerminalConverters:
public class TplXValueConverterService extends DefaultTerminalConverters
{
@ValueConverter(rule = "DEFINE_REFERENCE")
public IValueConverter<String> defineReferenceValueConverter() {
return new AbstractNullSafeConverter<String>() {
@Override
protected String internalToValue(String string, INode node)
throws ValueConverterException {
return string.startsWith("$") ? string.substring(1) : string;
}
@Override
protected String internalToString(String value) {
if (GrammarUtil.getAllKeywords(getGrammar()).contains(value)) {
return "$"+value;
}
return value;
}
};
}
}
|
|
|
|
|
|
Re: Unable to incorporate default IValueConverters [message #716940 is a reply to message #716921] |
Thu, 18 August 2011 20:56 |
|
Wow, thanks for the detective work. I changed the DEFINE_REFERENCE terminal rule to this Data Type Rule and no other changes were req'd - it simply worked!
DEFINE_REFERENCE returns ecore::EString:
'$' ID
;
Woohoo! Oh yeah, I also had to add this to the top of the grammar:
import "http://www.eclipse.org/emf/2002/Ecore" as ecore
|
|
|
Powered by
FUDForum. Page generated in 0.03743 seconds