lexText static method

Function? lexText(
  1. QueryLexer lexer
)

Implementation

static Function? lexText(QueryLexer lexer) {
  while (true) {
    String char = lexer.next();

    if (char == EOS) {
      return lexEOS;
    }

    // Escape character is '\'
    if (char.codeUnitAt(0) == 92) {
      lexer.escapeCharacter();
      continue;
    }

    if (char == ":") {
      return lexField;
    }

    if (char == "~") {
      lexer.backup();
      if (lexer.width() > 0) {
        lexer.emit(TERM);
      }
      return lexEditDistance;
    }

    if (char == "^") {
      lexer.backup();
      if (lexer.width() > 0) {
        lexer.emit(TERM);
      }
      return lexBoost;
    }

    // "+" indicates term presence is required
    // checking for length to ensure that only
    // leading "+" are considered
    if (char == "+" && lexer.width() == 1) {
      lexer.emit(PRESENCE);
      return lexText;
    }

    // "-" indicates term presence is prohibited
    // checking for length to ensure that only
    // leading "-" are considered
    if (char == "-" && lexer.width() == 1) {
      lexer.emit(PRESENCE);
      return lexText;
    }

    if (termSeparator.hasMatch(char)) {
      return lexTerm;
    }
  }
}