consume method

  1. @override
void consume()
override

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() {
  if (_index >= size) {
    // assert this.LA(1) == Token.EOF
    throw ('cannot consume EOF');
  }
  _index += 1;
}