lexicallyFirst method

Token lexicallyFirst(
  1. List<Token> tokens

Compare the given tokens to find the token that appears first in the source being parsed. That is, return the left-most of all of the tokens. The list must be non-null, but the elements of the list are allowed to be null. Return the token with the smallest offset, or null if the list is empty or if all of the elements of the list are null.


static Token lexicallyFirst(List<Token> tokens) {
  Token first = null;
  int offset = -1;
  int length = tokens.length;
  for (int i = 0; i < length; i++) {
    Token token = tokens[i];
    if (token != null && (offset < 0 || token.offset < offset)) {
      first = token;
      offset = token.offset;
  return first;