fix a few unit tests.

This commit is contained in:
Terence Parr 2012-07-31 19:09:40 -07:00
parent 3d2cbe087d
commit feb41eee15
4 changed files with 16 additions and 9 deletions

View File

@ -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<GrammarAST,GrammarAST> pair : litAliases) {
GrammarAST litAST = pair.b;
if ( lit.equals(litAST.getText()) ) continue nextLit;
if ( litAliases!=null ) {
for (Pair<GrammarAST,GrammarAST> pair : litAliases) {
GrammarAST litAST = pair.b;
if ( lit.equals(litAST.getText()) ) continue nextLit;
}
}
// create for each literal: (RULE <uniquename> (BLOCK (ALT <lit>))
String rname = combinedGrammar.getStringLiteralLexerRuleName(lit);

View File

@ -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) {

View File

@ -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<String> tokenTypes = new ArrayList<String>();
int ttype;
boolean hitEOF = false;

View File

@ -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();