forked from jasder/antlr
Listen for issues reported by StringTemplate, report them as warnings
This commit is contained in:
parent
fc3bb61d2d
commit
a50c8d9088
|
@ -4,6 +4,7 @@ December 11, 2012
|
|||
|
||||
* Add -long-messages option; only show exceptions with errors when set
|
||||
* "warning treated as error" is a one-off error
|
||||
* Listen for issues reported by StringTemplate, report them as warnings
|
||||
|
||||
December 2, 2012
|
||||
|
||||
|
|
|
@ -39,10 +39,12 @@ import org.antlr.v4.tool.Grammar;
|
|||
import org.stringtemplate.v4.AutoIndentWriter;
|
||||
import org.stringtemplate.v4.NumberRenderer;
|
||||
import org.stringtemplate.v4.ST;
|
||||
import org.stringtemplate.v4.STErrorListener;
|
||||
import org.stringtemplate.v4.STGroup;
|
||||
import org.stringtemplate.v4.STGroupFile;
|
||||
import org.stringtemplate.v4.STWriter;
|
||||
import org.stringtemplate.v4.StringRenderer;
|
||||
import org.stringtemplate.v4.misc.STMessage;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Writer;
|
||||
|
@ -116,6 +118,31 @@ public class CodeGenerator {
|
|||
templates = new STGroupFile(TEMPLATE_ROOT+"/"+language+"/"+language+".stg");
|
||||
templates.registerRenderer(Integer.class, new NumberRenderer());
|
||||
templates.registerRenderer(String.class, new StringRenderer());
|
||||
templates.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) {
|
||||
tool.errMgr.toolError(ErrorType.STRING_TEMPLATE_WARNING, msg.cause, msg.toString());
|
||||
}
|
||||
});
|
||||
}
|
||||
catch (IllegalArgumentException iae) {
|
||||
tool.errMgr.toolError(ErrorType.CANNOT_CREATE_TARGET_GENERATOR,
|
||||
|
|
|
@ -61,6 +61,8 @@ public enum ErrorType {
|
|||
INTERNAL_ERROR(20, "internal error: <arg> <arg2><if(exception&&verbose)>: <exception>" +
|
||||
"<stackTrace; separator=\"\\n\"><endif>", ErrorSeverity.ERROR),
|
||||
TOKENS_FILE_SYNTAX_ERROR(21, ".tokens file syntax error <arg>:<arg2>", ErrorSeverity.ERROR),
|
||||
STRING_TEMPLATE_WARNING(22, "template error: <arg> <arg2><if(exception&&verbose)>: <exception>" +
|
||||
"<stackTrace; separator=\"\\n\"><endif>", ErrorSeverity.WARNING),
|
||||
|
||||
// Code generation errors
|
||||
MISSING_CODE_GEN_TEMPLATES(30, "can't find code generation templates: <arg>", ErrorSeverity.ERROR),
|
||||
|
|
Loading…
Reference in New Issue