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
72
73
74
|
#ifndef SKHD_TOKENIZE_H
#define SKHD_TOKENIZE_H
static const char *modifier_flags_str[] =
{
"alt", "lalt", "ralt",
"shift", "lshift", "rshift",
"cmd", "lcmd", "rcmd",
"ctrl", "lctrl", "rctrl",
"fn", "hyper",
};
static const char *literal_keycode_str[] =
{
"return", "tab", "space",
"backspace", "escape", "delete",
"home", "end", "pageup",
"pagedown", "insert", "left",
"right", "up", "down",
"f1", "f2", "f3",
"f4", "f5", "f6",
"f7", "f8", "f9",
"f10", "f11", "f12",
"f13", "f14", "f15",
"f16", "f17", "f18",
"f19", "f20",
};
enum token_type
{
Token_Identifier,
Token_Activate,
Token_Command,
Token_Modifier,
Token_Literal,
Token_Key_Hex,
Token_Key,
Token_Decl,
Token_Comma,
Token_Insert,
Token_Plus,
Token_Dash,
Token_Arrow,
Token_Unknown,
Token_EndOfStream,
};
struct token
{
enum token_type type;
char *text;
unsigned length;
unsigned line;
unsigned cursor;
};
struct tokenizer
{
char *buffer;
char *at;
unsigned line;
unsigned cursor;
};
void tokenizer_init(struct tokenizer *tokenizer, char *buffer);
struct token get_token(struct tokenizer *tokenizer);
struct token peek_token(struct tokenizer tokenizer);
int token_equals(struct token token, const char *match);
#endif
|