From feb41eee15a97d490fb6a870b7a8a9b1b686b8e9 Mon Sep 17 00:00:00 2001 From: Terence Parr Date: Tue, 31 Jul 2012 19:09:40 -0700 Subject: [PATCH] fix a few unit tests. --- .../org/antlr/v4/tool/GrammarTransformPipeline.java | 10 ++++++---- .../src/org/antlr/v4/tool/interp/LexerInterpreter.java | 8 +++++++- tool/test/org/antlr/v4/test/BaseTest.java | 2 +- tool/test/org/antlr/v4/test/TestATNInterpreter.java | 5 ++--- 4 files changed, 16 insertions(+), 9 deletions(-) diff --git a/tool/src/org/antlr/v4/tool/GrammarTransformPipeline.java b/tool/src/org/antlr/v4/tool/GrammarTransformPipeline.java index db1084052..cc41130f3 100644 --- a/tool/src/org/antlr/v4/tool/GrammarTransformPipeline.java +++ b/tool/src/org/antlr/v4/tool/GrammarTransformPipeline.java @@ -358,12 +358,14 @@ public class GrammarTransformPipeline { // add strings from combined grammar (and imported grammars) into lexer // put them first as they are keywords; must resolve ambigs to these rules // tool.log("grammar", "strings from parser: "+stringLiterals); -nextLit: + nextLit: for (String lit : stringLiterals) { // if lexer already has a rule for literal, continue - for (Pair pair : litAliases) { - GrammarAST litAST = pair.b; - if ( lit.equals(litAST.getText()) ) continue nextLit; + if ( litAliases!=null ) { + for (Pair pair : litAliases) { + GrammarAST litAST = pair.b; + if ( lit.equals(litAST.getText()) ) continue nextLit; + } } // create for each literal: (RULE (BLOCK (ALT )) String rname = combinedGrammar.getStringLiteralLexerRuleName(lit); diff --git a/tool/src/org/antlr/v4/tool/interp/LexerInterpreter.java b/tool/src/org/antlr/v4/tool/interp/LexerInterpreter.java index f48e72944..c38be3ca0 100644 --- a/tool/src/org/antlr/v4/tool/interp/LexerInterpreter.java +++ b/tool/src/org/antlr/v4/tool/interp/LexerInterpreter.java @@ -38,6 +38,8 @@ import org.antlr.v4.runtime.Token; import org.antlr.v4.runtime.TokenFactory; import org.antlr.v4.runtime.TokenSource; import org.antlr.v4.runtime.atn.LexerATNSimulator; +import org.antlr.v4.runtime.atn.PredictionContextCache; +import org.antlr.v4.runtime.dfa.DFA; import org.antlr.v4.tool.LexerGrammar; public class LexerInterpreter implements TokenSource { @@ -48,6 +50,10 @@ public class LexerInterpreter implements TokenSource { /** How to create token objects */ protected TokenFactory _factory = CommonTokenFactory.DEFAULT; + protected static final DFA[] _decisionToDFA = new DFA[1]; + protected static final PredictionContextCache _sharedContextCache = + new PredictionContextCache(); + public LexerInterpreter(LexerGrammar g, String inputString) { this(g); setInput(inputString); @@ -56,7 +62,7 @@ public class LexerInterpreter implements TokenSource { public LexerInterpreter(LexerGrammar g) { Tool antlr = new Tool(); antlr.process(g,false); - interp = new LexerATNSimulator(g.atn,null,null); + interp = new LexerATNSimulator(g.atn,_decisionToDFA,_sharedContextCache); } public void setInput(String inputString) { diff --git a/tool/test/org/antlr/v4/test/BaseTest.java b/tool/test/org/antlr/v4/test/BaseTest.java index 6bd0e6ec7..f00818752 100644 --- a/tool/test/org/antlr/v4/test/BaseTest.java +++ b/tool/test/org/antlr/v4/test/BaseTest.java @@ -212,7 +212,7 @@ public abstract class BaseTest { CharStream input, boolean adaptive) { - LexerATNSimulator interp = new LexerATNSimulator(atn,null,null); + LexerATNSimulator interp = new LexerATNSimulator(atn,new DFA[1],null); List tokenTypes = new ArrayList(); int ttype; boolean hitEOF = false; diff --git a/tool/test/org/antlr/v4/test/TestATNInterpreter.java b/tool/test/org/antlr/v4/test/TestATNInterpreter.java index 7f2e57b47..e6b36e42f 100644 --- a/tool/test/org/antlr/v4/test/TestATNInterpreter.java +++ b/tool/test/org/antlr/v4/test/TestATNInterpreter.java @@ -6,6 +6,7 @@ import org.antlr.v4.runtime.atn.ATN; import org.antlr.v4.runtime.atn.ATNState; import org.antlr.v4.runtime.atn.BlockStartState; import org.antlr.v4.runtime.atn.LexerATNSimulator; +import org.antlr.v4.runtime.dfa.DFA; import org.antlr.v4.runtime.misc.IntegerList; import org.antlr.v4.tool.DOTGenerator; import org.antlr.v4.tool.Grammar; @@ -271,13 +272,11 @@ public class TestATNInterpreter extends BaseTest { int expected) { ATN lexatn = createATN(lg); - LexerATNSimulator lexInterp = new LexerATNSimulator(lexatn,null,null); + LexerATNSimulator lexInterp = new LexerATNSimulator(lexatn,new DFA[1],null); IntegerList types = getTokenTypesViaATN(inputString, lexInterp); System.out.println(types); - semanticProcess(lg); g.importVocab(lg); - semanticProcess(g); ParserATNFactory f = new ParserATNFactory(g); ATN atn = f.createATN();