small improvement in error msg

This commit is contained in:
Terence Parr 2012-11-17 16:07:40 -08:00
parent 78c75ee5e4
commit e366f00820
1 changed files with 8 additions and 6 deletions

View File

@ -138,18 +138,20 @@ public class TestRig {
// System.out.println("exec "+grammarName+"."+startRuleName);
String lexerName = grammarName+"Lexer";
ClassLoader cl = Thread.currentThread().getContextClassLoader();
Class<? extends Lexer> lexerClass;
Class<? extends Lexer> lexerClass = null;
try {
lexerClass = cl.loadClass(lexerName).asSubclass(Lexer.class);
}
catch (java.lang.ClassNotFoundException cnfe) {
// might be pure lexer grammar; no Lexer suffix then
lexerName = grammarName;
lexerClass = cl.loadClass(lexerName).asSubclass(Lexer.class);
}
if ( lexerClass==null ) {
System.err.println("Can't load "+lexerName);
return;
try {
lexerClass = cl.loadClass(lexerName).asSubclass(Lexer.class);
}
catch (ClassNotFoundException cnfe2) {
System.err.println("Can't load "+lexerName+" as lexer or parser");
return;
}
}
Constructor<? extends Lexer> lexerCtor = lexerClass.getConstructor(CharStream.class);