LT method
Get the Token instance associated with the value returned by
LA. This method has the same pre- and post-conditions as
IntStream.LA. In addition, when the preconditions of this method
are met, the return value is non-null and the value of
LT(k).getType()==LA(k)
.
TODO: in this doc it says that is non-null, but the implementation says otherwise
Se also: ntStream.LA
Implementation
@override
Token? LT(int k) {
//System.out.println("enter LT("+k+")");
lazyInit();
if (k == 0) return null;
if (k < 0) return LB(-k);
var i = p;
var n = 1; // we know tokens[p] is a good one
// find k good tokens
while (n < k) {
// skip off-channel tokens, but make sure to not look past EOF
if (sync(i + 1)) {
i = nextTokenOnChannel(i + 1, channel);
}
n++;
}
// if ( i>range ) range = i;
return tokens[i];
}