From c5ade128fd30592c6949f6b7039be2a8853ba706 Mon Sep 17 00:00:00 2001 From: Terence Parr Date: Thu, 6 Sep 2012 17:09:47 -0700 Subject: [PATCH] made a better error message when they target was not available and also I bail out of the code generation process. --- tool/src/org/antlr/v4/Tool.java | 2 +- tool/src/org/antlr/v4/codegen/CodeGenPipeline.java | 2 ++ tool/src/org/antlr/v4/codegen/CodeGenerator.java | 2 +- tool/src/org/antlr/v4/tool/ErrorType.java | 4 +++- 4 files changed, 7 insertions(+), 3 deletions(-) diff --git a/tool/src/org/antlr/v4/Tool.java b/tool/src/org/antlr/v4/Tool.java index 9e5ce1066..7af1642ca 100644 --- a/tool/src/org/antlr/v4/Tool.java +++ b/tool/src/org/antlr/v4/Tool.java @@ -79,7 +79,7 @@ import java.util.Map; import java.util.concurrent.CopyOnWriteArrayList; public class Tool { - public String VERSION = "4.0b1"; + public static final String VERSION = "4.0b1"; public static final String GRAMMAR_EXTENSION = ".g4"; public static final String LEGACY_GRAMMAR_EXTENSION = ".g"; diff --git a/tool/src/org/antlr/v4/codegen/CodeGenPipeline.java b/tool/src/org/antlr/v4/codegen/CodeGenPipeline.java index 9c08144e0..24ecf2029 100644 --- a/tool/src/org/antlr/v4/codegen/CodeGenPipeline.java +++ b/tool/src/org/antlr/v4/codegen/CodeGenPipeline.java @@ -42,6 +42,8 @@ public class CodeGenPipeline { public void process() { CodeGenerator gen = new CodeGenerator(g); + if ( gen.templates==null ) return; + if ( g.isLexer() ) { ST lexer = gen.generateLexer(); if ( g.tool.launch_ST_inspector ) lexer.inspect(); diff --git a/tool/src/org/antlr/v4/codegen/CodeGenerator.java b/tool/src/org/antlr/v4/codegen/CodeGenerator.java index a62a69a86..7c8b13691 100644 --- a/tool/src/org/antlr/v4/codegen/CodeGenerator.java +++ b/tool/src/org/antlr/v4/codegen/CodeGenerator.java @@ -118,7 +118,7 @@ public class CodeGenerator { } catch (IllegalArgumentException iae) { tool.errMgr.toolError(ErrorType.CANNOT_CREATE_TARGET_GENERATOR, - iae, + null, language); } } diff --git a/tool/src/org/antlr/v4/tool/ErrorType.java b/tool/src/org/antlr/v4/tool/ErrorType.java index 11bd9808d..7f446ce88 100644 --- a/tool/src/org/antlr/v4/tool/ErrorType.java +++ b/tool/src/org/antlr/v4/tool/ErrorType.java @@ -28,6 +28,8 @@ */ package org.antlr.v4.tool; +import org.antlr.v4.Tool; + /** * A complex enumeration of all the error messages that the tool can issue. * @@ -61,7 +63,7 @@ public enum ErrorType { // Code generation errors MISSING_CODE_GEN_TEMPLATES(30, "can't find code generation templates: ", ErrorSeverity.ERROR), - CANNOT_CREATE_TARGET_GENERATOR(31, "cannot create target code generator: ", ErrorSeverity.ERROR), + CANNOT_CREATE_TARGET_GENERATOR(31, "ANTLR cannot generate code as of version "+ Tool.VERSION, ErrorSeverity.ERROR), CODE_TEMPLATE_ARG_ISSUE(32, "code generation template has missing, misnamed, or incomplete arg list; missing ", ErrorSeverity.ERROR), CODE_GEN_TEMPLATES_INCOMPLETE(33, "missing code generation template ", ErrorSeverity.ERROR), NO_MODEL_TO_TEMPLATE_MAPPING(34, "no mapping to template name for output model class ", ErrorSeverity.ERROR),