summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--source/csv_parser.c6
-rw-r--r--source/engine.c2
-rw-r--r--source/lexer.c44
-rw-r--r--source/lexer.h4
4 files changed, 17 insertions, 39 deletions
diff --git a/source/csv_parser.c b/source/csv_parser.c
index 048e089..6679d2f 100644
--- a/source/csv_parser.c
+++ b/source/csv_parser.c
@@ -22,11 +22,5 @@ internal csv_table *
22parse_csv(token *tokens, csv_table *table) 22parse_csv(token *tokens, csv_table *table)
23{ 23{
24 24
25
26
27
28
29
30
31 return NULL; 25 return NULL;
32} 26}
diff --git a/source/engine.c b/source/engine.c
index 8f701e3..fe609e9 100644
--- a/source/engine.c
+++ b/source/engine.c
@@ -13,7 +13,7 @@ int main(int c, char **v)
13{ 13{
14 if(c < 2) return -999; 14 if(c < 2) return -999;
15 15
16 b32 running = 0; 16 local_persist b32 running = 1;
17 17
18 mem_arena *global_arena = arena_create(MiB(30)); 18 mem_arena *global_arena = arena_create(MiB(30));
19 csv_table *global_table = PushStruct(global_arena, csv_table); 19 csv_table *global_table = PushStruct(global_arena, csv_table);
diff --git a/source/lexer.c b/source/lexer.c
index c84a831..decfb7a 100644
--- a/source/lexer.c
+++ b/source/lexer.c
@@ -34,61 +34,47 @@ is_delimiter(u8 point)
34internal token * 34internal token *
35tokenize_csv(string8 buffer, mem_arena *arena) 35tokenize_csv(string8 buffer, mem_arena *arena)
36{ 36{
37 s32 count = 0;
38 string8 **tokens = PushString(arena, buffer.size);
39 37
40 b32 FL = TRUE; 38 b32 FL = TRUE;
41 39
42 if(buffer.size < 0) return NULL; 40 if(buffer.size < 0) return NULL;
43 for(s32 index = 0; 41 for(s32 index = 0; buffer.data[index] != '\0'; ++index)
44 buffer.data[index] != '\0';
45 ++index)
46 { 42 {
47 csv_row *row = PushStruct(arena, csv_row);
48 token *tok = PushStruct(arena, token); 43 token *tok = PushStruct(arena, token);
49
50 u8 point = buffer.data[index]; 44 u8 point = buffer.data[index];
51 45
52 u8 *start = buffer.data; 46 s32 start = 0;
53 u8 *end = NULL; 47 s32 end = 0;
54 48
55 unused(row); 49 if(is_whitespace(point))
50 {
51 print("csv file is invalid");
52 return NULL;
53 }
56 54
57 switch(point) 55 switch(point)
58 { 56 {
59 case('\n'): 57 case('\n'):
60 { 58 {
61 59 if(FL) tok->flags |= END_FL;
62 if(FL)
63 {
64 FL = FALSE;
65 tok->flags |= END_FL;
66 }
67
68 break; 60 break;
69
70 } 61 }
71 62
72 case(','): 63 case(','):
73 { 64 {
74 end = start - 1; 65 end = index - 1;
66 start = index + 1;
75 break; 67 break;
76 } 68 }
77
78 default: 69 default:
79 { 70 {
80 printf("point: %c\n", point);
81 count++;
82 break; 71 break;
83 } 72 }
84 } 73 }
85 74
86 token->lexeme = String8Cast(start, end - start); 75 tok->lexeme = String8Cast(&buffer.data[start], end - start);
87 76 tok->next = tok;
88 *tokens = token;
89 ++tokens;
90
91
92 return NULL;
93 } 77 }
78
79 return NULL;
94} 80}
diff --git a/source/lexer.h b/source/lexer.h
index 7bafc0d..c950a58 100644
--- a/source/lexer.h
+++ b/source/lexer.h
@@ -16,7 +16,6 @@ enum token_type
16 TOKEN_UNDEFINED = 255, 16 TOKEN_UNDEFINED = 255,
17 TOKEN_IDENTIFIER, 17 TOKEN_IDENTIFIER,
18 TOKEN_VALUE, 18 TOKEN_VALUE,
19
20}; 19};
21 20
22typedef struct token token; 21typedef struct token token;
@@ -25,8 +24,7 @@ struct token
25 string8 lexeme; 24 string8 lexeme;
26 token_type type; 25 token_type type;
27 token_flags flags; 26 token_flags flags;
27 token *next;
28}; 28};
29 29
30
31
32#endif /* ENGINE_LEXER_H */ 30#endif /* ENGINE_LEXER_H */