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
11
namespace
smollergraph
{
12
13
// The kinds of token in our subset of Cypher.
14
enum 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
22
struct
Token
{
23
TokenKind
kind
;
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.
32
absl::StatusOr<std::vector<Token>>
Lex
(std::string_view query);
33
34
}
// namespace smollergraph
35
36
#endif
// SMOLLERGRAPH_LEXER_H_
smollergraph
Definition
api.h:11
smollergraph::TokenKind
TokenKind
The kinds of token in our subset of Cypher.
Definition
lexer.h:14
smollergraph::TokenKind::kSymbol
@ kSymbol
smollergraph::TokenKind::kEnd
@ kEnd
smollergraph::TokenKind::kWord
@ kWord
smollergraph::TokenKind::kNumber
@ kNumber
smollergraph::ValueType::kString
@ kString
smollergraph::Lex
absl::StatusOr< std::vector< Token > > Lex(std::string_view query)
Splits a query into tokens, ending with a kEnd token.
Definition
lexer.cc:25
smollergraph::Token
Definition
lexer.h:22
smollergraph::Token::text
std::string text
Definition
lexer.h:24
smollergraph::Token::kind
TokenKind kind
Definition
lexer.h:23
smollergraph::Token::at
size_t at
Where the token starts in the query, for errors.
Definition
lexer.h:26
include
smollergraph
lexer.h
Generated by
1.9.8