From 894a77168dd5194538a1731d9c5ae15befba0bed Mon Sep 17 00:00:00 2001 From: Terence Parr Date: Sun, 5 Feb 2012 10:14:04 -0800 Subject: [PATCH] rename atn sim, add error message to TestRig --- .../Java/src/org/antlr/v4/runtime/Parser.java | 2 +- .../v4/runtime/atn/ParserATNPathFinder.java | 2 +- ...Simulator.java => ParserATNSimulator.java} | 6 ++--- .../src/org/antlr/v4/runtime/dfa/DFA.java | 4 +-- .../org/antlr/v4/runtime/misc/TestRig.java | 27 +++++++++++-------- .../v4/tool/interp/ParserInterpreter.java | 10 +++---- .../antlr/v4/test/TestATNDeserialization.java | 4 +-- .../v4/test/TestATNParserPrediction.java | 2 +- 8 files changed, 28 insertions(+), 29 deletions(-) rename runtime/Java/src/org/antlr/v4/runtime/atn/{v2ParserATNSimulator.java => ParserATNSimulator.java} (99%) diff --git a/runtime/Java/src/org/antlr/v4/runtime/Parser.java b/runtime/Java/src/org/antlr/v4/runtime/Parser.java index 313ee0df6..cc36f2be6 100644 --- a/runtime/Java/src/org/antlr/v4/runtime/Parser.java +++ b/runtime/Java/src/org/antlr/v4/runtime/Parser.java @@ -38,7 +38,7 @@ import java.util.ArrayList; import java.util.List; /** This is all the parsing support code essentially; most of it is error recovery stuff. */ -public abstract class Parser extends Recognizer> { +public abstract class Parser extends Recognizer> { public class TraceListener implements ParseTreeListener { @Override public void enterEveryRule(ParserRuleContext ctx) { diff --git a/runtime/Java/src/org/antlr/v4/runtime/atn/ParserATNPathFinder.java b/runtime/Java/src/org/antlr/v4/runtime/atn/ParserATNPathFinder.java index f21e95b04..ab04bb0a3 100644 --- a/runtime/Java/src/org/antlr/v4/runtime/atn/ParserATNPathFinder.java +++ b/runtime/Java/src/org/antlr/v4/runtime/atn/ParserATNPathFinder.java @@ -43,7 +43,7 @@ import java.util.HashSet; import java.util.List; import java.util.Set; -public class ParserATNPathFinder extends v2ParserATNSimulator { +public class ParserATNPathFinder extends ParserATNSimulator { public ParserATNPathFinder(@Nullable Parser parser, @NotNull ATN atn) { super(parser, atn); } diff --git a/runtime/Java/src/org/antlr/v4/runtime/atn/v2ParserATNSimulator.java b/runtime/Java/src/org/antlr/v4/runtime/atn/ParserATNSimulator.java similarity index 99% rename from runtime/Java/src/org/antlr/v4/runtime/atn/v2ParserATNSimulator.java rename to runtime/Java/src/org/antlr/v4/runtime/atn/ParserATNSimulator.java index 9068c1c47..51b31e458 100755 --- a/runtime/Java/src/org/antlr/v4/runtime/atn/v2ParserATNSimulator.java +++ b/runtime/Java/src/org/antlr/v4/runtime/atn/ParserATNSimulator.java @@ -225,7 +225,7 @@ import java.util.*; * when closure operations fall off the end of the rule that * holds the decision were evaluating */ -public class v2ParserATNSimulator extends ATNSimulator { +public class ParserATNSimulator extends ATNSimulator { public static boolean debug = false; public static boolean dfa_debug = false; public static boolean retry_debug = false; @@ -242,11 +242,11 @@ public class v2ParserATNSimulator extends ATNSimulator { public final DFA[] decisionToDFA; /** Testing only! */ - public v2ParserATNSimulator(@NotNull ATN atn) { + public ParserATNSimulator(@NotNull ATN atn) { this(null, atn); } - public v2ParserATNSimulator(@Nullable Parser parser, @NotNull ATN atn) { + public ParserATNSimulator(@Nullable Parser parser, @NotNull ATN atn) { super(atn); this.parser = parser; // ctxToDFAs = new HashMap(); diff --git a/runtime/Java/src/org/antlr/v4/runtime/dfa/DFA.java b/runtime/Java/src/org/antlr/v4/runtime/dfa/DFA.java index 415d29784..b3b41bd70 100644 --- a/runtime/Java/src/org/antlr/v4/runtime/dfa/DFA.java +++ b/runtime/Java/src/org/antlr/v4/runtime/dfa/DFA.java @@ -28,10 +28,8 @@ */ package org.antlr.v4.runtime.dfa; -import org.antlr.v4.runtime.Token; import org.antlr.v4.runtime.TokenStream; import org.antlr.v4.runtime.atn.*; -import org.antlr.v4.runtime.misc.IntervalSet; import org.antlr.v4.runtime.misc.NotNull; import org.antlr.v4.runtime.misc.Nullable; @@ -83,7 +81,7 @@ public class DFA { // return states; // } - public List> getATNStatesAlongPath(v2ParserATNSimulator atn, + public List> getATNStatesAlongPath(ParserATNSimulator atn, List dfaStates, TokenStream input, int start, int stop) { diff --git a/runtime/Java/src/org/antlr/v4/runtime/misc/TestRig.java b/runtime/Java/src/org/antlr/v4/runtime/misc/TestRig.java index 829d2510e..cae2de3e7 100644 --- a/runtime/Java/src/org/antlr/v4/runtime/misc/TestRig.java +++ b/runtime/Java/src/org/antlr/v4/runtime/misc/TestRig.java @@ -60,8 +60,8 @@ public class TestRig { 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] [-trace] [input-filename]"); + " [-tokens] [-print] [-gui] [-ps file.ps] [-encoding encodingname] [-trace]"+ + " [input-filename]"); return; } int i=0; @@ -155,17 +155,22 @@ public class TestRig { parser.setTrace(trace); - Method startRule = parserClass.getMethod(startRuleName, (Class[])null); - ParserRuleContext tree = (ParserRuleContext)startRule.invoke(parser, (Object[])null); + try { + Method startRule = parserClass.getMethod(startRuleName, (Class[])null); + ParserRuleContext tree = (ParserRuleContext)startRule.invoke(parser, (Object[])null); - if ( printTree ) { - System.out.println(tree.toStringTree(parser)); + if ( printTree ) { + System.out.println(tree.toStringTree(parser)); + } + if ( gui ) { + tree.inspect(parser); + } + if ( psFile!=null ) { + tree.save(parser, psFile); // Generate postscript + } } - if ( gui ) { - tree.inspect(parser); - } - if ( psFile!=null ) { - tree.save(parser, psFile); // Generate postscript + catch (NoSuchMethodException nsme) { + System.err.println("No method for rule "+startRuleName+" or it has arguments"); } } finally { diff --git a/tool/src/org/antlr/v4/tool/interp/ParserInterpreter.java b/tool/src/org/antlr/v4/tool/interp/ParserInterpreter.java index 66b9899b4..55683426f 100644 --- a/tool/src/org/antlr/v4/tool/interp/ParserInterpreter.java +++ b/tool/src/org/antlr/v4/tool/interp/ParserInterpreter.java @@ -33,14 +33,10 @@ import org.antlr.v4.Tool; import org.antlr.v4.runtime.*; import org.antlr.v4.runtime.atn.*; import org.antlr.v4.runtime.dfa.DFA; -import org.antlr.v4.runtime.misc.IntervalSet; import org.antlr.v4.runtime.misc.NotNull; import org.antlr.v4.runtime.misc.Nullable; import org.antlr.v4.tool.Grammar; -import java.util.HashSet; -import java.util.Set; - public class ParserInterpreter { class DummyParser extends Parser { public Grammar g; @@ -61,7 +57,7 @@ public class ParserInterpreter { } protected Grammar g; - protected v2ParserATNSimulator atnSimulator; + protected ParserATNSimulator atnSimulator; protected TokenStream input; public ParserInterpreter(@NotNull Grammar g) { @@ -71,7 +67,7 @@ public class ParserInterpreter { public ParserInterpreter(@NotNull Grammar g, @NotNull TokenStream input) { Tool antlr = new Tool(); antlr.process(g,false); - atnSimulator = new v2ParserATNSimulator(new DummyParser(g, input), g.atn); + atnSimulator = new ParserATNSimulator(new DummyParser(g, input), g.atn); } public int predictATN(@NotNull DFA dfa, @NotNull SymbolStream input, @@ -104,7 +100,7 @@ public class ParserInterpreter { } } - public v2ParserATNSimulator getATNSimulator() { + public ParserATNSimulator getATNSimulator() { return atnSimulator; } diff --git a/tool/test/org/antlr/v4/test/TestATNDeserialization.java b/tool/test/org/antlr/v4/test/TestATNDeserialization.java index c306fd536..f3816f6ee 100644 --- a/tool/test/org/antlr/v4/test/TestATNDeserialization.java +++ b/tool/test/org/antlr/v4/test/TestATNDeserialization.java @@ -3,7 +3,7 @@ package org.antlr.v4.test; import org.antlr.v4.automata.ATNSerializer; import org.antlr.v4.misc.Utils; import org.antlr.v4.runtime.atn.ATN; -import org.antlr.v4.runtime.atn.v2ParserATNSimulator; +import org.antlr.v4.runtime.atn.ParserATNSimulator; import org.antlr.v4.tool.Grammar; import org.antlr.v4.tool.LexerGrammar; import org.junit.Test; @@ -147,7 +147,7 @@ public class TestATNDeserialization extends BaseTest { ATN atn = createATN(g); char[] data = Utils.toCharArray(ATNSerializer.getSerialized(g, atn)); String atnData = ATNSerializer.getDecoded(g, atn); - ATN atn2 = v2ParserATNSimulator.deserialize(data); + ATN atn2 = ParserATNSimulator.deserialize(data); String atn2Data = ATNSerializer.getDecoded(g, atn2); assertEquals(atnData, atn2Data); diff --git a/tool/test/org/antlr/v4/test/TestATNParserPrediction.java b/tool/test/org/antlr/v4/test/TestATNParserPrediction.java index f85a5f413..4e9ba3ead 100644 --- a/tool/test/org/antlr/v4/test/TestATNParserPrediction.java +++ b/tool/test/org/antlr/v4/test/TestATNParserPrediction.java @@ -541,7 +541,7 @@ public class TestATNParserPrediction extends BaseTest { // System.out.println(dot.getDOT(atn.ruleToStartState.get(g.getRule("b")))); // System.out.println(dot.getDOT(atn.ruleToStartState.get(g.getRule("e")))); - v2ParserATNSimulator interp = new v2ParserATNSimulator(atn); + ParserATNSimulator interp = new ParserATNSimulator(atn); List types = getTokenTypesViaATN(inputString, lexInterp); System.out.println(types); TokenStream input = new IntTokenStream(types);