get to compile

[git-p4: depot-paths = "//depot/code/antlr4/main/": change = 8662]
This commit is contained in:
parrt 2011-06-18 10:35:31 -08:00
parent bb02ed151e
commit 1a17eb3be1
8 changed files with 35 additions and 120 deletions

View File

@ -28,11 +28,7 @@
package org.antlr.v4.runtime;
import org.antlr.runtime.BitSet;
import java.util.ArrayList;
import java.util.List;
import java.util.NoSuchElementException;
import java.util.*;
/** Buffer all input tokens but do on-demand fetching of new tokens from
* lexer. Useful when the parser or lexer has to set context/mode info before
@ -195,14 +191,14 @@ public class BufferedTokenStream implements TokenStream {
public List getTokens() { return tokens; }
public List getTokens(int start, int stop) {
return getTokens(start, stop, (BitSet)null);
return getTokens(start, stop, (Set<Integer>)null);
}
/** Given a start and stop index, return a List of all tokens in
* the token type BitSet. Return null if no tokens were found. This
* method looks at both on and off channel tokens.
*/
public List getTokens(int start, int stop, BitSet types) {
public List getTokens(int start, int stop, Set<Integer> types) {
if ( p == -1 ) setup();
if ( stop>=tokens.size() ) stop=tokens.size()-1;
if ( start<0 ) start=0;
@ -212,7 +208,7 @@ public class BufferedTokenStream implements TokenStream {
List<Token> filteredTokens = new ArrayList<Token>();
for (int i=start; i<=stop; i++) {
Token t = tokens.get(i);
if ( types==null || types.member(t.getType()) ) {
if ( types==null || types.contains(t.getType()) ) {
filteredTokens.add(t);
}
}
@ -222,12 +218,10 @@ public class BufferedTokenStream implements TokenStream {
return filteredTokens;
}
public List getTokens(int start, int stop, List types) {
return getTokens(start,stop,new BitSet(types));
}
public List getTokens(int start, int stop, int ttype) {
return getTokens(start,stop,BitSet.of(ttype));
HashSet<Integer> s = new HashSet<Integer>(ttype);
s.add(ttype);
return getTokens(start,stop, s);
}
public String getSourceName() { return tokenSource.getSourceName(); }

View File

@ -134,7 +134,7 @@ public abstract class Lexer extends Recognizer<LexerSharedState, LexerInterprete
}
public void pushMode(int m) {
// System.out.println("pushMode "+m);
System.out.println("pushMode "+m);
if ( state.modeStack==null ) state.modeStack = new QStack<Integer>();
state.modeStack.push(state.mode);
mode(m);
@ -142,7 +142,7 @@ public abstract class Lexer extends Recognizer<LexerSharedState, LexerInterprete
public int popMode() {
if ( state.modeStack==null ) throw new EmptyStackException();
// System.out.println("popMode back to "+state.modeStack.peek());
System.out.println("popMode back to "+state.modeStack.peek());
mode( state.modeStack.pop() );
return state.mode;
}

View File

@ -6,8 +6,8 @@ import org.antlr.v4.runtime.dfa.*;
/** "dup" of ParserInterpreter */
public class LexerInterpreter extends ATNInterpreter {
public static boolean debug = false;
public static boolean dfa_debug = false;
public static boolean debug = true;
public static boolean dfa_debug = true;
public static final int NUM_EDGES = 255;
protected Lexer recog;

View File

@ -1,79 +1,2 @@
/*
* @(#)SerializationTester.java 1.5 03/12/19
*
* Copyright 2004 Sun Microsystems, Inc. All rights reserved.
* SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
*/
import org.antlr.v4.runtime.Lexer;
import org.antlr.v4.runtime.CharStream;
import org.antlr.v4.runtime.LexerSharedState;
import org.antlr.v4.runtime.Token;
import org.antlr.v4.runtime.TokenStream;
import org.antlr.v4.runtime.*;
import org.antlr.v4.runtime.atn.*;
import org.antlr.v4.runtime.dfa.DFA;
import org.antlr.v4.runtime.misc.*;
import org.antlr.runtime.*;
public class T extends Lexer {
public static final int
EOR=1, STRING_START=4, WS=5, STRING=6, ANY=7;
public static final int DEFAULT_MODE = 0;
public static final int STRING_MODE = 1;
public static final String[] tokenNames = {
"<INVALID>", "<INVALID>", "<INVALID>",
"EOR", "STRING_START", "WS", "STRING", "ANY"
};
public static final String[] ruleNames = {
"<INVALID>",
"STRING_START", "WS", "STRING", "ANY"
};
public T(CharStream input) {
this(input, new LexerSharedState());
}
public T(CharStream input, LexerSharedState state) {
super(input,state);
_interp = new LexerInterpreter(this,_ATN);
}
public String getGrammarFileName() { return "T.java"; }
@Override
public String[] getTokenNames() { return tokenNames; }
@Override
public String[] getRuleNames() { return ruleNames; }
@Override
public ATN getATN() { return _ATN; }
public void action(int ruleIndex, int actionIndex) {
switch ( actionIndex ) {
case 1 : pushMode(STRING_MODE); more(); break;
case 2 : skip(); break;
case 3 : popMode(); break;
case 4 : more(); break;
}
}
public static final String _serializedATN =
"\030\012\032\06\00\06\00\02\01\07\01\02\02\07\02\02\03\07\03\02\04"+
"\07\04\01\01\01\01\01\01\01\02\01\02\01\02\01\02\01\02\03\02\010\02"+
"\01\03\01\03\01\03\01\04\01\04\01\04\04\02\04\01\04\05\02\06\06\03"+
"\010\07\04\02\00\01\00\031\00\02\01\00\00\00\04\01\00\00\01\06\01"+
"\00\00\01\010\01\00\00\02\012\01\00\00\04\022\01\00\00\06\024\01\00"+
"\00\010\027\01\00\00\012\013\05\042\00\013\014\01\00\00\014\03\01"+
"\00\00\015\016\05\040\00\016\023\01\00\00\017\020\05\012\00\020\021"+
"\01\00\00\021\023\01\00\00\022\015\01\00\00\022\017\01\00\00\023\05"+
"\01\00\00\024\025\05\042\00\025\026\01\00\00\026\07\01\00\00\027\030"+
"\013\00\00\030\031\01\00\00\031\011\01\00\00\03\00\01\022";
public static final ATN _ATN =
ATNInterpreter.deserialize(_serializedATN.toCharArray());
static {
org.antlr.v4.tool.DOTGenerator dot = new org.antlr.v4.tool.DOTGenerator(null);
//System.out.println(dot.getDOT(_ATN.decisionToATNState.get(0)));
}
}

View File

@ -29,6 +29,7 @@ package org.antlr.v4.test;
import org.antlr.v4.Tool;
import org.antlr.v4.automata.*;
import org.antlr.v4.misc.Utils;
import org.antlr.v4.runtime.*;
import org.antlr.v4.runtime.atn.*;
@ -79,13 +80,11 @@ public abstract class BaseTest {
protected org.antlr.v4.Tool newTool(String[] args) {
Tool tool = new Tool(args);
tool.setOutputDirectory(tmpdir);
return tool;
}
protected Tool newTool() {
org.antlr.v4.Tool tool = new Tool();
tool.setOutputDirectory(tmpdir);
org.antlr.v4.Tool tool = new Tool(new String[] {"-o", tmpdir});
return tool;
}

View File

@ -1,10 +1,9 @@
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.ParserInterpreter;
import org.antlr.v4.tool.Grammar;
import org.antlr.v4.tool.LexerGrammar;
import org.antlr.v4.runtime.atn.*;
import org.antlr.v4.tool.*;
import org.junit.Test;
public class TestATNDeserialization extends BaseTest {
@ -116,11 +115,11 @@ public class TestATNDeserialization extends BaseTest {
protected void checkDeserializationIsStable(Grammar g) {
ATN atn = createATN(g);
char[] data = Utils.toCharArray(atn.getSerialized());
String atnData = atn.getDecoded();
char[] data = Utils.toCharArray(ATNSerializer.getSerialized(atn));
String atnData = ATNSerializer.getDecoded(atn);
ATN atn2 = ParserInterpreter.deserialize(data);
atn2.g = g;
String atn2Data = atn2.getDecoded();
String atn2Data = ATNSerializer.getDecoded(atn2);
assertEquals(atnData, atn2Data);
}

View File

@ -579,7 +579,6 @@ public class TestATNParserPrediction extends BaseTest {
nvae.printStackTrace(System.err);
}
DFA dfa = interp.decisionToDFA[decision];
ATNInterpreter.dump(dfa,g);
assertEquals(dfaString[i], dfa.toString(g.getTokenDisplayNames()));
}
}

View File

@ -1,5 +1,6 @@
package org.antlr.v4.test;
import org.antlr.v4.automata.ATNSerializer;
import org.antlr.v4.runtime.atn.ATN;
import org.antlr.v4.tool.*;
import org.junit.Test;
@ -26,7 +27,7 @@ public class TestATNSerialization extends BaseTest {
"4->5 ATOM 4,0\n" +
"5->1 EPSILON 0,0\n";
ATN atn = createATN(g);
String result = atn.getDecoded();
String result = ATNSerializer.getDecoded(atn);
assertEquals(expecting, result);
}
@ -48,7 +49,7 @@ public class TestATNSerialization extends BaseTest {
"2->3 NOT_ATOM 3,0\n" +
"3->1 EPSILON 0,0\n";
ATN atn = createATN(g);
String result = atn.getDecoded();
String result = ATNSerializer.getDecoded(atn);
assertEquals(expecting, result);
}
@ -70,7 +71,7 @@ public class TestATNSerialization extends BaseTest {
"2->3 WILDCARD 0,0\n" +
"3->1 EPSILON 0,0\n";
ATN atn = createATN(g);
String result = atn.getDecoded();
String result = ATNSerializer.getDecoded(atn);
assertEquals(expecting, result);
}
@ -105,7 +106,7 @@ public class TestATNSerialization extends BaseTest {
"9->1 EPSILON 0,0\n" +
"0:8\n";
ATN atn = createATN(g);
String result = atn.getDecoded();
String result = ATNSerializer.getDecoded(atn);
assertEquals(expecting, result);
}
@ -153,7 +154,7 @@ public class TestATNSerialization extends BaseTest {
"15->1 EPSILON 0,0\n" +
"0:14\n";
ATN atn = createATN(g);
String result = atn.getDecoded();
String result = ATNSerializer.getDecoded(atn);
assertEquals(expecting, result);
}
@ -190,7 +191,7 @@ public class TestATNSerialization extends BaseTest {
"1:4\n" +
"2:6\n";
ATN atn = createATN(g);
String result = atn.getDecoded();
String result = ATNSerializer.getDecoded(atn);
assertEquals(expecting, result);
}
@ -221,7 +222,7 @@ public class TestATNSerialization extends BaseTest {
"6->7 ATOM 3,0\n" +
"7->3 EPSILON 0,0\n";
ATN atn = createATN(g);
String result = atn.getDecoded();
String result = ATNSerializer.getDecoded(atn);
assertEquals(expecting, result);
}
@ -254,7 +255,7 @@ public class TestATNSerialization extends BaseTest {
"8->4 EPSILON 0,0\n" +
"0:0\n";
ATN atn = createATN(lg);
String result = atn.getDecoded();
String result = ATNSerializer.getDecoded(atn);
assertEquals(expecting, result);
}
@ -277,7 +278,7 @@ public class TestATNSerialization extends BaseTest {
"4->2 EPSILON 0,0\n" +
"0:0\n";
ATN atn = createATN(lg);
String result = atn.getDecoded();
String result = ATNSerializer.getDecoded(atn);
assertEquals(expecting, result);
}
@ -312,7 +313,7 @@ public class TestATNSerialization extends BaseTest {
"2:5\n" +
"3:7\n";
ATN atn = createATN(lg);
String result = atn.getDecoded();
String result = ATNSerializer.getDecoded(atn);
assertEquals(expecting, result);
}
@ -359,7 +360,7 @@ public class TestATNSerialization extends BaseTest {
"14->6 EPSILON 0,0\n" +
"0:0\n";
ATN atn = createATN(lg);
String result = atn.getDecoded();
String result = ATNSerializer.getDecoded(atn);
assertEquals(expecting, result);
}
@ -383,7 +384,7 @@ public class TestATNSerialization extends BaseTest {
"4->2 EPSILON 0,0\n" +
"0:0\n";
ATN atn = createATN(lg);
String result = atn.getDecoded();
String result = ATNSerializer.getDecoded(atn);
assertEquals(expecting, result);
}
@ -407,7 +408,7 @@ public class TestATNSerialization extends BaseTest {
"4->2 EPSILON 0,0\n" +
"0:0\n";
ATN atn = createATN(lg);
String result = atn.getDecoded();
String result = ATNSerializer.getDecoded(atn);
assertEquals(expecting, result);
}
@ -436,7 +437,7 @@ public class TestATNSerialization extends BaseTest {
"6->2 EPSILON 0,0\n" +
"0:0\n";
ATN atn = createATN(lg);
String result = atn.getDecoded();
String result = ATNSerializer.getDecoded(atn);
assertEquals(expecting, result);
}
@ -487,7 +488,7 @@ public class TestATNSerialization extends BaseTest {
"1:1\n" +
"2:2\n";
ATN atn = createATN(lg);
String result = atn.getDecoded();
String result = ATNSerializer.getDecoded(atn);
assertEquals(expecting, result);
}