use of org.stringtemplate.v4.STGroup in project antlr4 by antlr.
the class Python2Target method loadTemplates.
@Override
protected STGroup loadTemplates() {
STGroup result = super.loadTemplates();
result.registerRenderer(String.class, new PythonStringRenderer(), true);
return result;
}
use of org.stringtemplate.v4.STGroup in project antlr4 by antlr.
the class CppTarget method loadTemplates.
@Override
protected STGroup loadTemplates() {
STGroup result = super.loadTemplates();
result.registerRenderer(Integer.class, new NumberRenderer());
result.registerRenderer(String.class, new StringRenderer());
result.setListener(new STErrorListener() {
@Override
public void compileTimeError(STMessage msg) {
reportError(msg);
}
@Override
public void runTimeError(STMessage msg) {
reportError(msg);
}
@Override
public void IOError(STMessage msg) {
reportError(msg);
}
@Override
public void internalError(STMessage msg) {
reportError(msg);
}
private void reportError(STMessage msg) {
getCodeGenerator().tool.errMgr.toolError(ErrorType.STRING_TEMPLATE_WARNING, msg.cause, msg.toString());
}
});
return result;
}
use of org.stringtemplate.v4.STGroup in project bndtools by bndtools.
the class StringTemplateEngine method compile.
private ST compile(STGroup group, String name, Resource resource) throws Exception {
ErrorBuffer errors = new ErrorBuffer();
group.setListener(errors);
ST st;
try {
loadRawTemplate(group, name, resource);
st = group.getInstanceOf(name);
} catch (Exception e) {
// Wrap the ST exception, which gives us no detail in its message
throw new IllegalArgumentException(String.format("Failed to compile template '%s': %s", name, errors.toString()));
}
if (st == null)
throw new Exception("Template name not loaded: " + name);
return st;
}
Aggregations