nextToken method

  1. @override
Token nextToken()

Return a token from this source; i.e., match a token on the char stream.

Implementation

@override
Token nextToken() {
  // Mark start location in char stream so unbuffered streams are
  // guaranteed at least have text of current token
  final tokenStartMarker = _input.mark();
  try {
    outer:
    while (true) {
      if (_hitEOF) {
        emitEOF();
        return _token!;
      }

      _token = null;
      channel = Token.DEFAULT_CHANNEL;
      tokenStartCharIndex = _input.index;
      tokenStartCharPositionInLine = interpreter!.charPositionInLine;
      tokenStartLine = interpreter!.line;
      _text = null;
      do {
        type = Token.INVALID_TYPE;
//				System.out.println("nextToken line "+tokenStartLine+" at "+((char)input.LA(1))+
//								   " in mode "+mode+
//								   " at index "+input.index());
        late int ttype;
        try {
          ttype = interpreter!.match(_input, mode_);
        } on LexerNoViableAltException catch (e) {
          notifyListeners(e); // report error
          recover(e);
          ttype = SKIP;
        }
        if (_input.LA(1) == IntStream.EOF) {
          _hitEOF = true;
        }
        if (type == Token.INVALID_TYPE) type = ttype;
        if (type == SKIP) {
          continue outer;
        }
      } while (type == MORE);
      if (_token == null) emit();
      return _token!;
    }
  } finally {
    // make sure we release marker after match or
    // unbuffered char stream will keep buffering
    _input.release(tokenStartMarker);
  }
}