Add IntervalSet.toIntegerList(), use IntegerStack to hold mode stack in Lexer
This commit is contained in:
parent
fa62570737
commit
3bf99d6d88
|
@ -29,9 +29,9 @@
|
|||
package org.antlr.v4.runtime;
|
||||
|
||||
import org.antlr.v4.runtime.atn.LexerATNSimulator;
|
||||
import org.antlr.v4.runtime.misc.IntegerStack;
|
||||
import org.antlr.v4.runtime.misc.Interval;
|
||||
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.ArrayList;
|
||||
import java.util.EmptyStackException;
|
||||
import java.util.List;
|
||||
|
@ -91,7 +91,7 @@ public abstract class Lexer extends Recognizer<Integer, LexerATNSimulator>
|
|||
/** The token type for the current token */
|
||||
public int _type;
|
||||
|
||||
public ArrayDeque<Integer> _modeStack = new ArrayDeque<Integer>();
|
||||
public final IntegerStack _modeStack = new IntegerStack();
|
||||
public int _mode = Lexer.DEFAULT_MODE;
|
||||
|
||||
/** You can set the text for the current token to override what is in
|
||||
|
|
|
@ -530,6 +530,20 @@ public class IntervalSet implements IntSet {
|
|||
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
|
||||
public List<Integer> toList() {
|
||||
List<Integer> values = new ArrayList<Integer>();
|
||||
|
@ -579,19 +593,7 @@ public class IntervalSet implements IntSet {
|
|||
}
|
||||
|
||||
public int[] toArray() {
|
||||
int[] values = new int[size()];
|
||||
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;
|
||||
return toIntegerList().toArray();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in New Issue