|
|
Re: IllegalArgumentException from converter initialization since 2.8.4 (bug 469805) [message #1708211 is a reply to message #1708140] |
Mon, 14 September 2015 16:17 |
Stephan Herrmann Messages: 1853 Registered: July 2009 |
Senior Member |
|
|
Hi Sebastian,
Quote:you registered an AbstractLexerBasedConverter for a data type rule, which is a parser rule. That cannot work ...
"Unfortunately", it works in my tool (seems to). Which simply means, I don't know how to detect if any changes that I would make now are really an improvement.
Quote: ...the exception that is now raised earlier than later ...
Can I force this exception somehow so that I'm able to test the issue?
Quote:You may want to implement your own converter for INT
Well, I kind-of have that, except that it's one converter for both interpretations of integer tokens:
public static class MyTerminalConverters extends DefaultTerminalConverters {
@ValueConverter(rule = "MYINT")
public IValueConverter<Integer> getMYINTConverter() {
return new DualINTValueConverter();
}
@ValueConverter(rule = "INT")
public IValueConverter<Integer> getINTConverter() {
return new DualINTValueConverter();
}
}
// an INT converter that copes with rules "MYINT" as well as "INT": at the lexical level we cannot distinguish!
static class DualINTValueConverter extends INTValueConverter {
@Override
protected void assertTokens(Integer value, TokenSource tokenSource, String escapedString) {
// copied from AbstractLexerBasedConverter
if (tokenSource == null)
return;
Token token = tokenSource.nextToken();
if (!escapedString.equals(token.getText())) {
throw createTokenContentMismatchException(value, escapedString, token);
}
// modified: accept for MYINT and INT:
String tokenRuleName = getRuleName(token);
if (!"INT".equals(tokenRuleName) && !"MYINT".equals(tokenRuleName)) {
throw createTokenTypeMismatchException(value, escapedString, token);
}
// --
Integer reparsedValue = toValue(token.getText(), null);
if (value != reparsedValue && !value.equals(reparsedValue)) {
throw createTokenContentMismatchException(value, escapedString, token);
}
}
}
I'm aware that this dual interpretation of the same lexical kind is a bit hackish. I'm just curious what bad can happen downstream, so I can test and protect against it.
thanks,
Stephan
|
|
|
Powered by
FUDForum. Page generated in 0.02766 seconds