Add IntervalSet.toIntegerList(), use IntegerStack to hold mode stack in Lexer

This commit is contained in:
Sam Harwell 2012-07-30 13:56:19 -05:00
parent fa62570737
commit 3bf99d6d88
2 changed files with 17 additions and 15 deletions

View File

@ -29,9 +29,9 @@
package org.antlr.v4.runtime; package org.antlr.v4.runtime;
import org.antlr.v4.runtime.atn.LexerATNSimulator; import org.antlr.v4.runtime.atn.LexerATNSimulator;
import org.antlr.v4.runtime.misc.IntegerStack;
import org.antlr.v4.runtime.misc.Interval; import org.antlr.v4.runtime.misc.Interval;
import java.util.ArrayDeque;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.EmptyStackException; import java.util.EmptyStackException;
import java.util.List; import java.util.List;
@ -91,7 +91,7 @@ public abstract class Lexer extends Recognizer<Integer, LexerATNSimulator>
/** The token type for the current token */ /** The token type for the current token */
public int _type; public int _type;
public ArrayDeque<Integer> _modeStack = new ArrayDeque<Integer>(); public final IntegerStack _modeStack = new IntegerStack();
public int _mode = Lexer.DEFAULT_MODE; public int _mode = Lexer.DEFAULT_MODE;
/** You can set the text for the current token to override what is in /** You can set the text for the current token to override what is in

View File

@ -530,6 +530,20 @@ public class IntervalSet implements IntSet {
return n; return n;
} }
public IntegerList toIntegerList() {
IntegerList values = new IntegerList(size());
int n = intervals.size();
for (int i = 0; i < n; i++) {
Interval I = intervals.get(i);
int a = I.a;
int b = I.b;
for (int v=a; v<=b; v++) {
values.add(v);
}
}
return values;
}
@Override @Override
public List<Integer> toList() { public List<Integer> toList() {
List<Integer> values = new ArrayList<Integer>(); List<Integer> values = new ArrayList<Integer>();
@ -579,19 +593,7 @@ public class IntervalSet implements IntSet {
} }
public int[] toArray() { public int[] toArray() {
int[] values = new int[size()]; return toIntegerList().toArray();
int n = intervals.size();
int j = 0;
for (int i = 0; i < n; i++) {
Interval I = intervals.get(i);
int a = I.a;
int b = I.b;
for (int v=a; v<=b; v++) {
values[j] = v;
j++;
}
}
return values;
} }
@Override @Override