diff options
Diffstat (limited to 'source/engine.c')
| -rw-r--r-- | source/engine.c | 89 |
1 files changed, 76 insertions, 13 deletions
diff --git a/source/engine.c b/source/engine.c index 9797d8a..106f113 100644 --- a/source/engine.c +++ b/source/engine.c | |||
| @@ -1,3 +1,6 @@ | |||
| 1 | |||
| 2 | |||
| 3 | |||
| 1 | #define B_TREE_IMPLEMENTATION | 4 | #define B_TREE_IMPLEMENTATION |
| 2 | #define BASE_UNITY | 5 | #define BASE_UNITY |
| 3 | #include "base/base_include.h" | 6 | #include "base/base_include.h" |
| @@ -33,7 +36,6 @@ is_delimiter(u8 point) | |||
| 33 | 36 | ||
| 34 | } | 37 | } |
| 35 | 38 | ||
| 36 | |||
| 37 | #include "b_tree.h" | 39 | #include "b_tree.h" |
| 38 | #include "csv_reader.h" | 40 | #include "csv_reader.h" |
| 39 | 41 | ||
| @@ -44,13 +46,48 @@ struct query_token | |||
| 44 | query_token *next; | 46 | query_token *next; |
| 45 | }; | 47 | }; |
| 46 | 48 | ||
| 49 | typedef struct query_token_list query_token_list; | ||
| 50 | struct query_token_list | ||
| 51 | { | ||
| 52 | query_token *start_token; | ||
| 53 | query_token *current_token; | ||
| 54 | }; | ||
| 55 | |||
| 56 | read_only global_variable | ||
| 57 | query_token nil_query_token = | ||
| 58 | { | ||
| 59 | .lexeme = {.data = NULL, .size = 0}, | ||
| 60 | .next = &nil_query_token | ||
| 61 | }; | ||
| 62 | |||
| 63 | |||
| 64 | read_only global_variable | ||
| 65 | query_token_list nil_query_token_list = | ||
| 66 | { | ||
| 67 | .start_token = &nil_query_token, | ||
| 68 | .current_token = &nil_query_token, | ||
| 69 | }; | ||
| 70 | |||
| 71 | internal b32 | ||
| 72 | is_nil_query_token(query_token *token) | ||
| 73 | { | ||
| 74 | return (token == &nil_query_token) || (token == NULL); | ||
| 75 | } | ||
| 76 | |||
| 77 | internal b32 | ||
| 78 | is_nil_query_token_list(query_token *token) | ||
| 79 | { | ||
| 80 | return (token == &nil_query_token) || (token == NULL); | ||
| 81 | } | ||
| 82 | |||
| 47 | 83 | ||
| 48 | // takes on line of the repl input | 84 | // takes on line of the repl input |
| 49 | internal query_token * | 85 | // return a reference to the passed list |
| 50 | query_tokenizer(mem_arena *arena, string8 *buffer) | 86 | internal query_token_list * |
| 87 | query_tokenizer(mem_arena *arena, string8 *buffer, query_token_list *list) | ||
| 51 | { | 88 | { |
| 52 | query_token *tok = PushStruct(arena, query_token); | 89 | b32 initialized = 0; |
| 53 | unused(tok); | 90 | unused(initialized); |
| 54 | 91 | ||
| 55 | for (u64 index = 0; index < buffer->size; ++index) | 92 | for (u64 index = 0; index < buffer->size; ++index) |
| 56 | { | 93 | { |
| @@ -69,23 +106,44 @@ query_tokenizer(mem_arena *arena, string8 *buffer) | |||
| 69 | // save the token | 106 | // save the token |
| 70 | // TODO(nasr): work on the string macros cuz no work | 107 | // TODO(nasr): work on the string macros cuz no work |
| 71 | { | 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 | } | ||
| 72 | 124 | ||
| 73 | s32 new_token_size = end - start; | 125 | s32 new_token_size = end - start; |
| 74 | 126 | ||
| 75 | tok->lexeme = PushString(arena, new_token_size); | 127 | new_token->lexeme = PushString(arena, new_token_size); |
| 76 | tok->lexeme.data = &buffer->data[index]; | 128 | new_token->lexeme.data = &buffer->data[index]; |
| 77 | tok->lexeme.size = new_token_size; | 129 | new_token->lexeme.size = new_token_size; |
| 130 | |||
| 131 | list->current_token->next = new_token; | ||
| 78 | 132 | ||
| 79 | tok->next = tok; | ||
| 80 | start = index + 1; | 133 | start = index + 1; |
| 81 | } | 134 | } |
| 82 | } | 135 | } |
| 83 | 136 | ||
| 84 | return tok; | 137 | return list; |
| 85 | } | 138 | } |
| 86 | 139 | ||
| 87 | int main(int count, char **value) | 140 | int main(int count, char **value) |
| 88 | { | 141 | { |
| 142 | |||
| 143 | #if 1 | ||
| 144 | unused(nil_query_token_list); | ||
| 145 | #endif | ||
| 146 | |||
| 89 | if(count < 2) value[1] = "./test/data.csv"; | 147 | if(count < 2) value[1] = "./test/data.csv"; |
| 90 | 148 | ||
| 91 | local_persist b32 running = 1; | 149 | local_persist b32 running = 1; |
| @@ -121,16 +179,21 @@ int main(int count, char **value) | |||
| 121 | lbuf_stringified.size = sizeof(lbuf) - 1; | 179 | lbuf_stringified.size = sizeof(lbuf) - 1; |
| 122 | } | 180 | } |
| 123 | 181 | ||
| 124 | query_tokenizer(global_arena, &lbuf_stringified); | 182 | query_token_list *qtl = PushStruct(global_arena, query_token_list); |
| 183 | |||
| 184 | query_tokenizer(global_arena, &lbuf_stringified, qtl); | ||
| 125 | } | 185 | } |
| 126 | 186 | ||
| 127 | { | 187 | { |
| 128 | read_csv(buffer); | 188 | read_csv(buffer); |
| 129 | token *tokens = tokenize_csv(buffer, global_arena); | 189 | |
| 190 | csv_token *tokens = tokenize_csv(buffer, global_arena); | ||
| 130 | 191 | ||
| 131 | assert_msg(tokens != NULL, "Tokens are NULL."); | 192 | assert_msg(tokens != NULL, "Tokens are NULL."); |
| 132 | 193 | ||
| 133 | b_tree *bt = parse_csv(global_arena, tokens); | 194 | csv_token_list *ctl = PushStruct(global_arena, csv_token_list); |
| 195 | b_tree *bt = parse_csv(global_arena, ctl); | ||
| 196 | |||
| 134 | b_tree_write(bt); | 197 | b_tree_write(bt); |
| 135 | } | 198 | } |
| 136 | 199 | ||
