consume method
Consumes the current symbol in the stream. This method has the following effects:
- Forward movement: The value of {@link #index index()} before calling this method is less than the value of {@code index()} after calling this method.
- Ordered lookahead: The value of {@code LA(1)} before calling this method becomes the value of {@code LA(-1)} after calling this method.
Note that calling this method does not guarantee that {@code index()} is incremented by exactly 1, as that would preclude the ability to implement filtering streams (e.g. CommonTokenStream which distinguishes between "on-channel" and "off-channel" tokens).
@throws IllegalStateException if an attempt is made to consume the end of the stream (i.e. if {@code LA(1)==}{@link #EOF EOF} before calling consume).
Implementation
@override
void consume() {
bool skipEofCheck;
if (p >= 0) {
if (fetchedEOF) {
// the last token in tokens is EOF. skip check if p indexes any
// fetched token except the last.
skipEofCheck = p < tokens.length - 1;
} else {
// no EOF token in tokens. skip check if p indexes a fetched token.
skipEofCheck = p < tokens.length;
}
} else {
// not yet initialized
skipEofCheck = false;
}
if (!skipEofCheck && LA(1) == IntStream.EOF) {
throw StateError('cannot consume EOF');
}
if (sync(p + 1)) {
p = adjustSeekIndex(p + 1);
}
}