builder.replaceElement(occurrence, "Other", new Expression() {
@Nullable
@Override
public Result calculateResult(ExpressionContext context) {
TemplateState state = TemplateManagerImpl.getTemplateState(context.getEditor());
assert state != null;
TextResult text = ObjectUtils.assertNotNull(state.getVariableValue("TokenText"));
String curText = StringUtil.unquoteString(text.getText());
if (ParserGeneratorUtil.isRegexpToken(curText)) {
return state.getVariableValue("TokenName");
}
else {
return new TextResult("'" + curText + "'");
}
}