add -diagnostics option to test rig.

This commit is contained in:
Terence Parr 2012-03-28 11:07:23 -07:00
parent 48b2e237d1
commit 447a5620f0
1 changed files with 8 additions and 2 deletions

View File

@ -53,6 +53,7 @@ import java.lang.reflect.Method;
* [-print] * [-print]
* [-tokens] [-gui] [-ps file.ps] * [-tokens] [-gui] [-ps file.ps]
* [-trace] * [-trace]
* [-diagnostics]
* [input-filename] * [input-filename]
*/ */
public class TestRig { public class TestRig {
@ -65,10 +66,12 @@ public class TestRig {
String psFile = null; String psFile = null;
boolean showTokens = false; boolean showTokens = false;
boolean trace = false; boolean trace = false;
boolean diagnostics = false;
String encoding = null; String encoding = null;
if ( args.length < 2 ) { if ( args.length < 2 ) {
System.err.println("java org.antlr.v4.runtime.misc.TestRig GrammarName startRuleName" + System.err.println("java org.antlr.v4.runtime.misc.TestRig GrammarName startRuleName" +
" [-tokens] [-print] [-gui] [-ps file.ps] [-encoding encodingname] [-trace]"+ " [-tokens] [-print] [-gui] [-ps file.ps] [-encoding encodingname]" +
" [-trace] [-diagnostics]"+
" [input-filename]"); " [input-filename]");
return; return;
} }
@ -96,6 +99,9 @@ public class TestRig {
else if ( arg.equals("-trace") ) { else if ( arg.equals("-trace") ) {
trace = true; trace = true;
} }
else if ( arg.equals("-diagnostics") ) {
diagnostics = true;
}
else if ( arg.equals("-encoding") ) { else if ( arg.equals("-encoding") ) {
if ( i>=args.length ) { if ( i>=args.length ) {
System.err.println("missing encoding on -encoding"); System.err.println("missing encoding on -encoding");
@ -155,7 +161,7 @@ public class TestRig {
Constructor<Parser> parserCtor = parserClass.getConstructor(TokenStream.class); Constructor<Parser> parserCtor = parserClass.getConstructor(TokenStream.class);
Parser parser = parserCtor.newInstance(tokens); Parser parser = parserCtor.newInstance(tokens);
parser.addErrorListener(new DiagnosticErrorListener()); if ( diagnostics ) parser.addErrorListener(new DiagnosticErrorListener());
if ( printTree || gui || psFile!=null ) { if ( printTree || gui || psFile!=null ) {
parser.setBuildParseTree(true); parser.setBuildParseTree(true);