forked from jasder/antlr
v4: Fix LookaheadStream ability to seek forward past the current location (via consume())
[git-p4: depot-paths = "//depot/code/antlr4/main/": change = 9395]
This commit is contained in:
parent
7774405ee3
commit
f64ecebd34
|
@ -145,12 +145,18 @@ public abstract class LookaheadStream<T> extends FastQueue<T> {
|
||||||
*/
|
*/
|
||||||
public void seek(int index) {
|
public void seek(int index) {
|
||||||
int bufferStartIndex = currentElementIndex - p;
|
int bufferStartIndex = currentElementIndex - p;
|
||||||
if (index < bufferStartIndex || index > currentElementIndex) {
|
if (index < bufferStartIndex) {
|
||||||
throw new UnsupportedOperationException("Cannot seek to the specified index.");
|
throw new UnsupportedOperationException("Cannot seek to the specified index.");
|
||||||
}
|
}
|
||||||
|
|
||||||
currentElementIndex = index;
|
if (index > currentElementIndex) {
|
||||||
p = index - bufferStartIndex;
|
for (int i = 0; i < currentElementIndex - index; i++) {
|
||||||
|
consume();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
currentElementIndex = index;
|
||||||
|
p = index - bufferStartIndex;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected T LB(int k) {
|
protected T LB(int k) {
|
||||||
|
|
Loading…
Reference in New Issue