Reputation: 11
Below is my Xtext file. I have an input {TestData1}/n{TestData2}/n{TestData3}. In this case after parsing my data gets changed to {TestData1}{TestData2}{TestData3} (the /n gets removed as part of the FREE_TEXT ValueConverter. I don't want them to get removed. How should I modify my FREE_TEXT to accomodate this use case. Please refer the FREE_TEXT terminal in the File, It is probably because of that one.
terminal EXT_INT: INT ('e'|'E')('-'|'+') INT;
terminal FREE_TEXT:
'}' ( '\\{' | !('{') )* ('{');
Code for parsing:
public class TestExpressionValueConverter extends DefaultTerminalConverters {
@ValueConverter(rule = "FREE_TEXT")
public IValueConverter<String> FREE_TEXT() {
return new IValueConverter<String>() {
@Override
public String toValue(String string, INode node) throws ValueConverterException {
String lineSeparator = System.getProperty("line.separator");
String result = string;
if (result.startsWith("}" + lineSeparator)) {
result = result.substring(1 + lineSeparator.length());
} else if (result.startsWith("}")) {
result = result.substring(1);
}
if (result.endsWith(lineSeparator + "{")) {
result = result.substring(0, result.length() - 1 - lineSeparator.length());
} else if (result.endsWith("{")) {
result = result.substring(0, result.length() - 1);
}
result = result.replace("\\\\", "\\");
result = result.replace("\\{", "{");
// System.out.println("Convert " + string + " => " + result);
return result;
}
@Override
public String toString(String value) throws ValueConverterException {
return "}" + value + "{";
}
};
}
}
Upvotes: 0
Views: 62