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,13 +145,19 @@ public abstract class LookaheadStream<T> extends FastQueue<T> {
|
|||
*/
|
||||
public void seek(int index) {
|
||||
int bufferStartIndex = currentElementIndex - p;
|
||||
if (index < bufferStartIndex || index > currentElementIndex) {
|
||||
if (index < bufferStartIndex) {
|
||||
throw new UnsupportedOperationException("Cannot seek to the specified index.");
|
||||
}
|
||||
|
||||
if (index > currentElementIndex) {
|
||||
for (int i = 0; i < currentElementIndex - index; i++) {
|
||||
consume();
|
||||
}
|
||||
} else {
|
||||
currentElementIndex = index;
|
||||
p = index - bufferStartIndex;
|
||||
}
|
||||
}
|
||||
|
||||
protected T LB(int k) {
|
||||
int bufferIndex = p - k;
|
||||
|
|
Loading…
Reference in New Issue