25absl::StatusOr<std::vector<Token>>
Lex(std::string_view query) {
26 std::vector<Token> tokens;
28 while (i < query.size()) {
31 if (std::isspace(
static_cast<unsigned char>(c))) {
33 }
else if (IsWordStart(c)) {
34 while (i < query.size() && IsWordPart(query[i])) ++i;
36 std::string(query.substr(start, i - start)), start});
37 }
else if (IsDigit(c)) {
38 while (i < query.size() && IsDigit(query[i])) ++i;
40 std::string(query.substr(start, i - start)), start});
41 }
else if (c ==
'\'' || c ==
'"') {
43 size_t end = query.find(c, i + 1);
44 if (end == std::string_view::npos) {
45 return absl::InvalidArgumentError(
46 absl::StrCat(
"no closing quote for the string at ", start));
49 std::string(query.substr(i + 1, end - i - 1)), start});
51 }
else if (std::string_view pair = query.substr(i, 2);
52 pair ==
"<=" || pair ==
">=" || pair ==
"<>") {
56 }
else if (std::string_view(
"()[]{}:,.-<>*=|").find(c) !=
57 std::string_view::npos) {
61 return absl::InvalidArgumentError(
62 absl::StrCat(
"unexpected ", std::string_view(&c, 1),
" at ", start));