summaryrefslogtreecommitdiff
path: root/source/engine.c
diff options
context:
space:
mode:
Diffstat (limited to 'source/engine.c')
-rw-r--r--source/engine.c210
1 files changed, 0 insertions, 210 deletions
diff --git a/source/engine.c b/source/engine.c
deleted file mode 100644
index 106f113..0000000
--- a/source/engine.c
+++ /dev/null
@@ -1,210 +0,0 @@
1
2
3
4#define B_TREE_IMPLEMENTATION
5#define BASE_UNITY
6#include "base/base_include.h"
7
8internal b32
9is_alpha(u8 point)
10{
11 return ((point >= 'a' && point <= 'z') || (point >= 'A' && point <= 'Z') || (point == '_'));
12}
13
14internal b32
15is_digit(u8 point)
16{
17 return (point >= '0' && point <= '9');
18}
19
20internal b32
21is_alpha_num(u8 point)
22{
23 return (is_alpha(point) || is_digit(point));
24}
25
26internal b32
27is_whitespace(u8 point)
28{
29 return (point == '\n' || point == '\r' || point == ' ' || point == '\t');
30}
31
32internal b32
33is_delimiter(u8 point)
34{
35 return (point == ',');
36
37}
38
39#include "b_tree.h"
40#include "csv_reader.h"
41
42typedef struct query_token query_token;
43struct query_token
44{
45 string8 lexeme;
46 query_token *next;
47};
48
49typedef struct query_token_list query_token_list;
50struct query_token_list
51{
52 query_token *start_token;
53 query_token *current_token;
54};
55
56read_only global_variable
57query_token nil_query_token =
58{
59 .lexeme = {.data = NULL, .size = 0},
60 .next = &nil_query_token
61};
62
63
64read_only global_variable
65query_token_list nil_query_token_list =
66{
67 .start_token = &nil_query_token,
68 .current_token = &nil_query_token,
69};
70
71internal b32
72is_nil_query_token(query_token *token)
73{
74 return (token == &nil_query_token) || (token == NULL);
75}
76
77internal b32
78is_nil_query_token_list(query_token *token)
79{
80 return (token == &nil_query_token) || (token == NULL);
81}
82
83
84// takes on line of the repl input
85// return a reference to the passed list
86internal query_token_list *
87query_tokenizer(mem_arena *arena, string8 *buffer, query_token_list *list)
88{
89 b32 initialized = 0;
90 unused(initialized);
91
92 for (u64 index = 0; index < buffer->size; ++index)
93 {
94 u8 codepoint = buffer->data[index];
95
96 if(codepoint == '\n' || codepoint == '\r') break;
97
98 s32 start = 0;
99 s32 end = 0;
100
101 if(is_whitespace(codepoint))
102 {
103 end = index;
104 }
105
106 // save the token
107 // TODO(nasr): work on the string macros cuz no work
108 {
109 query_token *new_token = PushStruct(arena, query_token);
110
111 //- initialize list
112 {
113 if(is_nil_query_token(list->start_token))
114 {
115 list->start_token = new_token;
116 list->current_token = new_token;
117 }
118 else
119 {
120 //- all we need to do - we dont track parents or what ever. this is a token stream not a tree
121 list->current_token->next = new_token;
122 }
123 }
124
125 s32 new_token_size = end - start;
126
127 new_token->lexeme = PushString(arena, new_token_size);
128 new_token->lexeme.data = &buffer->data[index];
129 new_token->lexeme.size = new_token_size;
130
131 list->current_token->next = new_token;
132
133 start = index + 1;
134 }
135 }
136
137 return list;
138}
139
140int main(int count, char **value)
141{
142
143#if 1
144 unused(nil_query_token_list);
145#endif
146
147 if(count < 2) value[1] = "./test/data.csv";
148
149 local_persist b32 running = 1;
150
151 mem_arena *global_arena = arena_create(MiB(30));
152
153 // NOTE(nasr): see note down below
154 // csv_table *global_table = PushStruct(global_arena, csv_table);
155
156 string8 buffer = load_file(global_arena, value[1]);
157
158 print("\nDatabase Engine\n");
159
160 for(;;)
161 {
162 if (running)
163 {
164 {
165 u8 *lbuf = PushArray(global_arena, u8, 256);
166 s32 err = os_read(STDIN_FD, lbuf, 256);
167
168 if(err < 0)
169 {
170 print("error reading from stdin");
171 }
172
173 // TODO(nasr): extract this later in the future and make a string copy function/macro
174 // @params (s32 lbuf_size , string8 lbuf_stringified)
175 s32 lbuf_size = sizeof(lbuf) - 1;
176 string8 lbuf_stringified = PushString(global_arena, lbuf_size);
177 {
178 memcpy(lbuf_stringified.data, lbuf, lbuf_size);
179 lbuf_stringified.size = sizeof(lbuf) - 1;
180 }
181
182 query_token_list *qtl = PushStruct(global_arena, query_token_list);
183
184 query_tokenizer(global_arena, &lbuf_stringified, qtl);
185 }
186
187 {
188 read_csv(buffer);
189
190 csv_token *tokens = tokenize_csv(buffer, global_arena);
191
192 assert_msg(tokens != NULL, "Tokens are NULL.");
193
194 csv_token_list *ctl = PushStruct(global_arena, csv_token_list);
195 b_tree *bt = parse_csv(global_arena, ctl);
196
197 b_tree_write(bt);
198 }
199
200
201 // NOTE(nasr): not sure on how to approach the b-tree and the table format thing
202 // we kind of want our table format i think? but i wouldnt be sure about the use case
203 // so we stick to the regular b_tree for now. commenting out the tables.
204
205 sleep(1);
206 }
207 }
208
209 return 0;
210}