-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtokenizer.h
71 lines (49 loc) · 1.14 KB
/
tokenizer.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#pragma once
#include <variant>
#include <optional>
#include <istream>
#include <regex>
#include <string>
#include "error.h"
struct SymbolToken {
std::string name;
bool operator==(const SymbolToken& other) const;
static bool StartsWith(char);
static bool Contains(char);
};
struct QuoteToken {
bool operator==(const QuoteToken&) const;
};
struct DotToken {
bool operator==(const DotToken&) const;
};
struct BooleanToken {
bool value;
bool operator==(const BooleanToken&) const;
};
enum class BracketToken { OPEN, CLOSE };
struct ConstantToken {
int value;
bool operator==(const ConstantToken& other) const;
};
using Token =
std::variant<ConstantToken, BracketToken, SymbolToken, QuoteToken, DotToken, BooleanToken>;
class Tokenizer {
public:
Tokenizer(std::istream* in);
bool IsEnd();
void Next();
Token GetToken();
private:
void Constant();
void Symbol();
void Bracket();
void Dot();
void Quote();
void Boolean();
bool GoodChar(char) const;
void CheckException() const;
std::istream* in_;
std::optional<Token> token_o_;
bool is_end_;
};