summaryrefslogtreecommitdiff
path: root/source/csv_reader.h
diff options
context:
space:
mode:
Diffstat (limited to 'source/csv_reader.h')
-rw-r--r--source/csv_reader.h69
1 files changed, 52 insertions, 17 deletions
diff --git a/source/csv_reader.h b/source/csv_reader.h
index 7f5bf06..f5205bf 100644
--- a/source/csv_reader.h
+++ b/source/csv_reader.h
@@ -1,15 +1,15 @@
1#ifndef ENGINE_LEXER_H 1#ifndef ENGINE_LEXER_H
2#define ENGINE_LEXER_H 2#define ENGINE_LEXER_H
3 3
4typedef enum token_flags token_flags; 4typedef enum csv_token_flags csv_token_flags;
5enum token_flags 5enum csv_token_flags
6{ 6{
7 START_FL = 1 << 1, 7 START_FL = 1 << 1,
8 END_FL = 1 << 2, 8 END_FL = 1 << 2,
9}; 9};
10 10
11typedef enum token_type token_type; 11typedef enum csv_token_type csv_token_type;
12enum token_type 12enum csv_token_type
13{ 13{
14 // first 255 tokens for ascii characters 14 // first 255 tokens for ascii characters
15 TOKEN_UNDEFINED = 255, 15 TOKEN_UNDEFINED = 255,
@@ -17,13 +17,13 @@ enum token_type
17 TOKEN_VALUE, 17 TOKEN_VALUE,
18}; 18};
19 19
20typedef struct token token; 20typedef struct csv_token csv_token;
21struct token 21struct csv_token
22{ 22{
23 string8 lexeme; 23 string8 lexeme;
24 token_type type; 24 csv_token_type type;
25 token_flags flags; 25 csv_token_flags flags;
26 token *next; 26 csv_token *next;
27}; 27};
28 28
29// NOTE(nasr): i dont think im going to use this. 29// NOTE(nasr): i dont think im going to use this.
@@ -46,6 +46,33 @@ struct csv_table
46 s32 row_count; 46 s32 row_count;
47}; 47};
48 48
49
50typedef struct csv_token_list csv_token_list;
51struct csv_token_list
52{
53 csv_token *start_token;
54 csv_token *end_token;
55
56};
57
58read_only global_variable
59csv_token nil_csv_token=
60{
61 .lexeme = {.data = NULL, .size =0},
62 .type = (csv_token_type)0,
63 .flags = 0,
64 .next = &nil_csv_token,
65
66};
67
68read_only global_variable
69csv_token_list nil_csv_token_list =
70{
71 .start_token = &nil_csv_token,
72 .end_token = &nil_csv_token,
73};
74
75
49read_only global_variable 76read_only global_variable
50csv_row nil_csv_row = 77csv_row nil_csv_row =
51{ 78{
@@ -67,14 +94,14 @@ csv_table nil_csv_table =
67// the lexer acts as a table builder from a csv file 94// the lexer acts as a table builder from a csv file
68// and parsing indivudal rows and columns 95// and parsing indivudal rows and columns
69// the next step would be building a the b-tree 96// the next step would be building a the b-tree
70internal token * 97internal csv_token *
71tokenize_csv(string8 buffer, mem_arena *arena) 98tokenize_csv(string8 buffer, mem_arena *arena)
72{ 99{
73 b32 FL = TRUE; 100 b32 FL = TRUE;
74 101
75 if(buffer.size < 0) return NULL; 102 if(buffer.size < 0) return NULL;
76 103
77 token *tok = PushStruct(arena, token); 104 csv_token *tok = PushStruct(arena, csv_token);
78 105
79 // URGENT(nasr): segfaulting because memcpy of strring value doesnt work dammit 106 // URGENT(nasr): segfaulting because memcpy of strring value doesnt work dammit
80 // NOPE ITS BEECAUSE WEE DONT LOAD CSV OR SOMTHING??? 107 // NOPE ITS BEECAUSE WEE DONT LOAD CSV OR SOMTHING???
@@ -126,22 +153,30 @@ read_csv(string8 buffer)
126} 153}
127 154
128internal b_tree * 155internal b_tree *
129parse_csv(mem_arena *arena, token *tok) 156parse_csv(mem_arena *arena, csv_token_list *ctl)
130{ 157{
131 b_tree *tree = PushStructZero(arena, b_tree); 158 b_tree *tree = PushStructZero(arena, b_tree);
132 b_tree_create(arena, tree); 159 b_tree_create(arena, tree);
133 160
134 for (; tok != NULL; tok = tok->next) 161 //- TODO(nasr): check initizalization or something tomorrow
162 {
163
164 }
165 // TODO(nasr): fix this logic tomorrow
166 csv_token *ct = PushStruct(arena, csv_token);
167
168 for (;ct != NULL; ct = ct->next)
135 { 169 {
136 // skip structural tokens, only index values 170 // skip structural ctens, only index values
137 if (tok->type != TOKEN_VALUE) 171 if (ct->type != TOKEN_VALUE)
138 { 172 {
139 continue; 173 continue;
140 } 174 }
141 175
142 // NOTE(nasr): payload is the token itself so the caller can reach 176 // NOTE(nasr): payload is the cten itself so the caller can reach
143 // row/col metadata without us having to copy it 177 // row/col metadata without us having to copy it
144 b_tree_insert(arena, tree, tok->lexeme, (void *)tok); 178 // NOTE(nasr): heh why do we void cast again?
179 b_tree_insert(arena, tree, ct->lexeme, (void *)ct);
145 } 180 }
146 181
147 return tree; 182 return tree;