Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added -trace to TestRig. fixed code gen issue for trace listener #2

Merged
merged 1 commit into from
Jan 31, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions runtime/Java/src/org/antlr/v4/runtime/misc/TestRig.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
/** 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 {
Expand All @@ -52,9 +56,12 @@ public static void main(String[] args) throws Exception {
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;
Expand All @@ -78,6 +85,9 @@ public static void main(String[] args) throws Exception {
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");
Expand Down Expand Up @@ -143,6 +153,8 @@ else if ( arg.equals("-ps") ) {
parser.setBuildParseTree(true);
}

parser.setTrace(trace);

Method startRule = parserClass.getMethod(startRuleName, (Class[])null);
ParserRuleContext<Token> tree = (ParserRuleContext<Token>)startRule.invoke(parser, (Object[])null);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
>>

Expand All @@ -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()>"
Expand Down