add new panic() method, though not yet used. revert to java target if cannot find specified target

This commit is contained in:
Terence Parr 2014-06-29 13:02:34 -07:00
parent 5bd415b195
commit 4f7f8538ac
3 changed files with 17 additions and 3 deletions

View File

@ -36,6 +36,7 @@ import org.antlr.v4.runtime.Token;
import org.antlr.v4.runtime.misc.NotNull;
import org.antlr.v4.tool.ErrorType;
import org.antlr.v4.tool.Grammar;
import org.antlr.v4.tool.ast.GrammarAST;
import org.stringtemplate.v4.AutoIndentWriter;
import org.stringtemplate.v4.ST;
import org.stringtemplate.v4.STGroup;
@ -83,12 +84,11 @@ public class CodeGenerator {
if (target == null) {
loadLanguageTarget(language);
}
return target;
}
public STGroup getTemplates() {
return getTarget().getTemplates();
return getTarget().getTemplates();
}
protected void loadLanguageTarget(String language) {
@ -123,6 +123,10 @@ public class CodeGenerator {
cnfe,
targetName);
}
if ( target == null ) {
// Try to fake our way through execution of the tool using the Java target object
target = new JavaTarget(this);
}
}
// CREATE TEMPLATES BY WALKING MODEL

View File

@ -318,6 +318,16 @@ public class ErrorManager {
e.printStackTrace(System.err);
}
public void panic(ErrorType errorType, Object... args) {
ToolMessage msg = new ToolMessage(errorType, args);
ST msgST = getMessageTemplate(msg);
String outputMsg = msgST.render();
if ( formatWantsSingleLineMessage() ) {
outputMsg = outputMsg.replace('\n', ' ');
}
panic(outputMsg);
}
public static void panic(String msg) {
rawError(msg);
panic();

View File

@ -147,7 +147,7 @@ public enum ErrorType {
* ANTLR cannot generate '<em>language</em>' code as of version
* <em>version</em></p>
*/
CANNOT_CREATE_TARGET_GENERATOR(31, "ANTLR cannot generate '<arg>' code as of version "+ Tool.VERSION, ErrorSeverity.ERROR),
CANNOT_CREATE_TARGET_GENERATOR(31, "ANTLR cannot generate '<arg>' code as of version "+ Tool.VERSION, ErrorSeverity.ERROR_ONE_OFF),
/**
* Compiler Error 32.
*