Search in sources :

Example 1 with NumberRenderer

use of org.stringtemplate.v4.NumberRenderer in project antlr4 by antlr.

the class CSharpTarget method loadTemplates.

@Override
protected STGroup loadTemplates() {
    // override the superclass behavior to put all C# templates in the same folder
    STGroup result = new STGroupFile(CodeGenerator.TEMPLATE_ROOT + "/CSharp/" + getLanguage() + STGroup.GROUP_FILE_EXTENSION);
    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;
}
Also used : STMessage(org.stringtemplate.v4.misc.STMessage) STGroup(org.stringtemplate.v4.STGroup) StringRenderer(org.stringtemplate.v4.StringRenderer) STGroupFile(org.stringtemplate.v4.STGroupFile) STErrorListener(org.stringtemplate.v4.STErrorListener) NumberRenderer(org.stringtemplate.v4.NumberRenderer)

Example 2 with NumberRenderer

use of org.stringtemplate.v4.NumberRenderer in project antlr4 by antlr.

the class Target method loadTemplates.

protected STGroup loadTemplates() {
    String groupFileName = CodeGenerator.TEMPLATE_ROOT + "/" + getLanguage() + "/" + getLanguage() + STGroup.GROUP_FILE_EXTENSION;
    STGroup result = null;
    try {
        result = new STGroupFile(groupFileName);
    } catch (IllegalArgumentException iae) {
        gen.tool.errMgr.toolError(ErrorType.MISSING_CODE_GEN_TEMPLATES, iae, language);
    }
    if (result == null)
        return null;
    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;
}
Also used : STMessage(org.stringtemplate.v4.misc.STMessage) STGroup(org.stringtemplate.v4.STGroup) StringRenderer(org.stringtemplate.v4.StringRenderer) STGroupFile(org.stringtemplate.v4.STGroupFile) STErrorListener(org.stringtemplate.v4.STErrorListener) NumberRenderer(org.stringtemplate.v4.NumberRenderer)

Example 3 with NumberRenderer

use of org.stringtemplate.v4.NumberRenderer 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;
}
Also used : STMessage(org.stringtemplate.v4.misc.STMessage) STGroup(org.stringtemplate.v4.STGroup) StringRenderer(org.stringtemplate.v4.StringRenderer) STErrorListener(org.stringtemplate.v4.STErrorListener) NumberRenderer(org.stringtemplate.v4.NumberRenderer)

Aggregations

NumberRenderer (org.stringtemplate.v4.NumberRenderer)3 STErrorListener (org.stringtemplate.v4.STErrorListener)3 STGroup (org.stringtemplate.v4.STGroup)3 StringRenderer (org.stringtemplate.v4.StringRenderer)3 STMessage (org.stringtemplate.v4.misc.STMessage)3 STGroupFile (org.stringtemplate.v4.STGroupFile)2