summaryrefslogtreecommitdiff
path: root/source/engine.c
diff options
context:
space:
mode:
Diffstat (limited to 'source/engine.c')
-rw-r--r--source/engine.c101
1 files changed, 93 insertions, 8 deletions
diff --git a/source/engine.c b/source/engine.c
index fe609e9..3527e27 100644
--- a/source/engine.c
+++ b/source/engine.c
@@ -1,17 +1,88 @@
1#define BASE_UNITY 1#define BASE_UNITY
2#include "base/base_include.h" 2#include "base/base_include.h"
3 3
4#include <stdio.h> 4internal b32
5is_alpha(u8 point)
6{
7 return ((point >= 'a' && point <= 'z') || (point >= 'A' && point <= 'Z') || (point == '_'));
8}
9
10internal b32
11is_digit(u8 point)
12{
13 return (point >= '0' && point <= '9');
14}
5 15
6#include "csv_parser.h" 16internal b32
7#include "lexer.h" 17is_alpha_num(u8 point)
18{
19 return (is_alpha(point) || is_digit(point));
20}
21
22internal b32
23is_whitespace(u8 point)
24{
25 return (point == '\n' || point == '\r' || point == ' ' || point == '\t');
26}
27
28internal b32
29is_delimiter(u8 point)
30{
31 return (point == ',');
32}
33
34#include "csv_reader.h"
35// #include "btree.h"
36
37typedef struct query_token query_token;
38struct query_token
39{
40 string8 *lexeme;
41 query_token *next;
42};
43
44
45// takes on line of the repl input
46internal query_token *
47query_tokenizer(mem_arena *arena, string8 *buffer)
48{
49 query_token *tok = PushStruct(arena, query_token);
50 unused(tok);
8 51
9#include "lexer.c" 52 for (u64 index = 0; index < buffer->size; ++index)
10#include "csv_parser.c" 53 {
54 u8 codepoint = buffer->data[index];
55
56 if(codepoint == '\n' || codepoint == '\r') break;
57
58 s32 start = 0;
59 s32 end = 0;
60
61 if(is_whitespace(codepoint))
62 {
63 end = index;
64 }
65
66 s32 new_token_size = end - start;
67
68 tok->lexeme->data = &buffer->data[index];
69 tok->lexeme->size = new_token_size;
70
71 tok->next = tok;
72 start = index + 1;
73
74 }
75
76 return tok;
77}
11 78
12int main(int c, char **v) 79int main(int c, char **v)
13{ 80{
14 if(c < 2) return -999; 81 if(c < 2)
82 {
83 print("bad file, setting default file\n");
84 }
85 else v[1] = "./test/customers-10000.csv";
15 86
16 local_persist b32 running = 1; 87 local_persist b32 running = 1;
17 88
@@ -26,13 +97,27 @@ int main(int c, char **v)
26 { 97 {
27 if (running) 98 if (running)
28 { 99 {
29 // TODO(nasr): check for return key
30 { 100 {
31 u8 line_buffer[256] = {}; 101 u8 line_buffer[256] = {};
32
33 s64 codepoint = os_read(STDIN_FD, line_buffer, 256); 102 s64 codepoint = os_read(STDIN_FD, line_buffer, 256);
34 unused(codepoint); 103 unused(codepoint);
104 for(s32 index = 0; index < 256; ++index)
105 {
106 if(line_buffer[index] == '\n')
107 {
108 print("exiting");
109 return 0;
110 }
111 else if(line_buffer[index] == ' ')
112 {
35 113
114 print("TODO(nasr): ");
115 }
116
117 }
118 }
119
120 {
36 read_csv(buffer); 121 read_csv(buffer);
37 token *tokens = tokenize_csv(buffer, global_arena); 122 token *tokens = tokenize_csv(buffer, global_arena);
38 global_table = parse_csv(tokens, global_table); 123 global_table = parse_csv(tokens, global_table);