forked from jasder/antlr
Merge pull request #2 from parrt/dev
added -trace to TestRig. fixed code gen issue for trace listener
This commit is contained in:
commit
433a30c584
|
@ -41,7 +41,11 @@ import java.lang.reflect.Method;
|
||||||
/** Run a lexer/parser combo, optionally printing tree string or generating
|
/** Run a lexer/parser combo, optionally printing tree string or generating
|
||||||
* postscript file. Optionally taking input file.
|
* 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 class TestRig {
|
||||||
public static void main(String[] args) throws Exception {
|
public static void main(String[] args) throws Exception {
|
||||||
|
@ -52,9 +56,12 @@ public class TestRig {
|
||||||
boolean gui = false;
|
boolean gui = false;
|
||||||
String psFile = null;
|
String psFile = null;
|
||||||
boolean showTokens = false;
|
boolean showTokens = false;
|
||||||
|
boolean trace = 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 [-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;
|
return;
|
||||||
}
|
}
|
||||||
int i=0;
|
int i=0;
|
||||||
|
@ -78,6 +85,9 @@ public class TestRig {
|
||||||
if ( arg.equals("-tokens") ) {
|
if ( arg.equals("-tokens") ) {
|
||||||
showTokens = true;
|
showTokens = true;
|
||||||
}
|
}
|
||||||
|
else if ( arg.equals("-trace") ) {
|
||||||
|
trace = 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");
|
||||||
|
@ -143,6 +153,8 @@ public class TestRig {
|
||||||
parser.setBuildParseTree(true);
|
parser.setBuildParseTree(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
parser.setTrace(trace);
|
||||||
|
|
||||||
Method startRule = parserClass.getMethod(startRuleName, (Class[])null);
|
Method startRule = parserClass.getMethod(startRuleName, (Class[])null);
|
||||||
ParserRuleContext<Token> tree = (ParserRuleContext<Token>)startRule.invoke(parser, (Object[])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) ::= <<
|
VisitorDispatchMethod(method) ::= <<
|
||||||
@Override
|
@Override
|
||||||
public void <if(method.isEnter)>enter<else>exit<endif>Rule(ParseTreeListener\<<InputSymbolType()>\> listener) {
|
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 */
|
/** If we don't know location of label def x, use this template */
|
||||||
labelref(x) ::= "<if(!x.isLocal)>_localctx.<endif><x.name>"
|
labelref(x) ::= "<if(!x.isLocal)>_localctx.<endif><x.name>"
|
||||||
|
|
||||||
// used for left-recursive rules
|
// used for left-recursive rules
|
||||||
recRuleDefArg() ::= "int _p"
|
recRuleDefArg() ::= "int _p"
|
||||||
recRuleArg() ::= "$_p"
|
recRuleArg() ::= "$_p"
|
||||||
recRuleAltPredicate(ruleName,opPrec) ::= "<opPrec> >= <recRuleArg()>"
|
recRuleAltPredicate(ruleName,opPrec) ::= "<opPrec> >= <recRuleArg()>"
|
||||||
|
|
Loading…
Reference in New Issue