forked from jasder/antlr
added -trace to TestRig. fixed code gen issue for trace listener
This commit is contained in:
parent
e90b322dd4
commit
1cc7ac3410
|
@ -41,7 +41,11 @@ import java.lang.reflect.Method;
|
|||
/** Run a lexer/parser combo, optionally printing tree string or generating
|
||||
* postscript file. Optionally taking input file.
|
||||
*
|
||||
* $ java org.antlr.v4.runtime.misc.TestRig GrammarName startRuleName [-print] [-tokens] [-gui] [-ps file.ps] [input-filename]
|
||||
* $ java org.antlr.v4.runtime.misc.TestRig GrammarName startRuleName
|
||||
* [-print]
|
||||
* [-tokens] [-gui] [-ps file.ps]
|
||||
* [-trace]
|
||||
* [input-filename]
|
||||
*/
|
||||
public class TestRig {
|
||||
public static void main(String[] args) throws Exception {
|
||||
|
@ -52,9 +56,12 @@ public class TestRig {
|
|||
boolean gui = false;
|
||||
String psFile = null;
|
||||
boolean showTokens = false;
|
||||
boolean trace = false;
|
||||
String encoding = null;
|
||||
if ( args.length < 2 ) {
|
||||
System.err.println("java org.antlr.v4.runtime.misc.TestRig GrammarName startRuleName [-print] [-tokens] [-gui] [-encoding encodingname] [-ps file.ps] [input-filename]");
|
||||
System.err.println("java org.antlr.v4.runtime.misc.TestRig GrammarName startRuleName" +
|
||||
" [-print] [-tokens] [-gui] [-encoding encodingname]" +
|
||||
" [-ps file.ps] [-trace] [input-filename]");
|
||||
return;
|
||||
}
|
||||
int i=0;
|
||||
|
@ -78,6 +85,9 @@ public class TestRig {
|
|||
if ( arg.equals("-tokens") ) {
|
||||
showTokens = true;
|
||||
}
|
||||
else if ( arg.equals("-trace") ) {
|
||||
trace = true;
|
||||
}
|
||||
else if ( arg.equals("-encoding") ) {
|
||||
if ( i>=args.length ) {
|
||||
System.err.println("missing encoding on -encoding");
|
||||
|
@ -143,6 +153,8 @@ public class TestRig {
|
|||
parser.setBuildParseTree(true);
|
||||
}
|
||||
|
||||
parser.setTrace(trace);
|
||||
|
||||
Method startRule = parserClass.getMethod(startRuleName, (Class[])null);
|
||||
ParserRuleContext<Token> tree = (ParserRuleContext<Token>)startRule.invoke(parser, (Object[])null);
|
||||
|
||||
|
|
|
@ -538,7 +538,7 @@ public static class <s.label>Context extends <currentRule.name>Context {
|
|||
VisitorDispatchMethod(method) ::= <<
|
||||
@Override
|
||||
public void <if(method.isEnter)>enter<else>exit<endif>Rule(ParseTreeListener\<<InputSymbolType()>\> listener) {
|
||||
if ( listener!=null ) ((<parser.grammarName>Listener)listener).<if(method.isEnter)>enter<else>exit<endif>Rule(this);
|
||||
if ( listener!=null && listener instanceof <parser.grammarName>Listener ) ((<parser.grammarName>Listener)listener).<if(method.isEnter)>enter<else>exit<endif>Rule(this);
|
||||
}
|
||||
>>
|
||||
|
||||
|
@ -547,7 +547,7 @@ AttributeDecl(d) ::= "<d.decl>"
|
|||
/** If we don't know location of label def x, use this template */
|
||||
labelref(x) ::= "<if(!x.isLocal)>_localctx.<endif><x.name>"
|
||||
|
||||
// used for left-recursive rules
|
||||
// used for left-recursive rules
|
||||
recRuleDefArg() ::= "int _p"
|
||||
recRuleArg() ::= "$_p"
|
||||
recRuleAltPredicate(ruleName,opPrec) ::= "<opPrec> >= <recRuleArg()>"
|
||||
|
|
Loading…
Reference in New Issue