@Override
	public void seek(int index) {
		if ( index<=p ) {
			p = index; // just jump; don't update stream state (line, ...)
			return;
		}
		// seek forward, consume until p hits index or n (whichever comes first)
		index = Math.min(index, n);
		while ( p<index ) {
			consume();
		}
	}
consume() ahead until p==index; can't just set p=index as we must
 update line and charPositionInLine. If we seek backwards, just set p
runtime/Java/src/org/antlr/v4/runtime/ANTLRInputStream.java