getHiddenTokensToLeft method

List<Token>? getHiddenTokensToLeft(
  1. int tokenIndex, [
  2. int channel = -1
])

Collect all tokens on specified channel to the left of the current token up until we see a token on DEFAULT_TOKEN_CHANNEL. If channel is -1, find any non default channel token.

Implementation

List<Token>? getHiddenTokensToLeft(int tokenIndex, [int channel = -1]) {
  lazyInit();
  if (tokenIndex < 0 || tokenIndex >= tokens.length) {
    throw RangeError.index(tokenIndex, tokens);
  }

  if (tokenIndex == 0) {
    // obviously no tokens can appear before the first token
    return null;
  }

  final prevOnChannel = previousTokenOnChannel(
    tokenIndex - 1,
    Lexer.DEFAULT_TOKEN_CHANNEL,
  );
  if (prevOnChannel == tokenIndex - 1) return null;
  // if none onchannel to left, prevOnChannel=-1 then from=0
  final from = prevOnChannel + 1;
  final to = tokenIndex - 1;

  return filterForChannel(from, to, channel);
}