nextToken function

((String, String), int) nextToken(
  1. String tagStr,
  2. int pos
)

Implementation

((String, String) token, int size) nextToken(String tagStr, int pos) {
  final c = tagStr[pos];
  if (c == ":") {
    if (tagStr.substring(pos, pos + 2) == "::") {
      return (("COLON", "::"), 2);
    }
    bail("Unrecognized token.");
  } else if (c == "<") {
    return (("LT", "<"), 1);
  } else if (c == ">") {
    return (("GT", ">"), 1);
  } else if (c == ",") {
    return (("COMMA", ","), 1);
  } else if (isWhiteSpace(c)) {
    var res = "";
    for (int i = pos; i < tagStr.length; i += 1) {
      final char = tagStr[i];
      if (isWhiteSpace(char)) {
        res = "$res$char";
      } else {
        break;
      }
    }
    return (("SPACE", res), res.length);
  } else if (isValidAlphabetic(c)) {
    var res = "";
    for (int i = pos; i < tagStr.length; i += 1) {
      final char = tagStr[i];
      if (isValidAlphabetic(char)) {
        res = "$res$char";
      } else {
        break;
      }
    }
    if (isGeneric(res)) {
      return (("GENERIC", res), res.length);
    }
    return (("IDENT", res), res.length);
  }
  throw ArgumentError("Unrecognized token.");
}