smollerGraph 0.20.2
A small graph database, from scratch
Loading...
Searching...
No Matches
lexer.h
Go to the documentation of this file.
1#ifndef SMOLLERGRAPH_LEXER_H_
2#define SMOLLERGRAPH_LEXER_H_
3
4#include <cstddef>
5#include <string>
6#include <string_view>
7#include <vector>
8
9#include "absl/status/statusor.h"
10
11namespace smollergraph {
12
13// The kinds of token in our subset of Cypher.
14enum class TokenKind {
15 kWord, // a keyword or a name: MATCH, a, name, EATS
16 kString, // a string, such as 'Red fox', without its quotes
17 kNumber, // a whole number, such as 2
18 kSymbol, // punctuation, such as ( or |, or a comparison, such as <=
19 kEnd, // after the last token
20};
21
22struct Token {
24 std::string text;
25 // Where the token starts in the query, for errors.
26 size_t at;
27};
28
29// Splits a query into tokens, ending with a kEnd token. Returns an error that
30// says what's wrong and where, at a character it doesn't know, or at a string
31// with no closing quote.
32absl::StatusOr<std::vector<Token>> Lex(std::string_view query);
33
34} // namespace smollergraph
35
36#endif // SMOLLERGRAPH_LEXER_H_
TokenKind
The kinds of token in our subset of Cypher.
Definition lexer.h:14
absl::StatusOr< std::vector< Token > > Lex(std::string_view query)
Splits a query into tokens, ending with a kEnd token.
Definition lexer.cc:25
std::string text
Definition lexer.h:24
TokenKind kind
Definition lexer.h:23
size_t at
Where the token starts in the query, for errors.
Definition lexer.h:26