summaryrefslogtreecommitdiff
path: root/source/lexer.c
diff options
context:
space:
mode:
Diffstat (limited to 'source/lexer.c')
-rw-r--r--source/lexer.c94
1 files changed, 94 insertions, 0 deletions
diff --git a/source/lexer.c b/source/lexer.c
new file mode 100644
index 0000000..c84a831
--- /dev/null
+++ b/source/lexer.c
@@ -0,0 +1,94 @@
1// the lexer acts as a table builder from a csv file
2// and parsing indivudal rows and columns
3// the next step would be building a the b-tree
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}
15
16internal b32
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
34internal token *
35tokenize_csv(string8 buffer, mem_arena *arena)
36{
37 s32 count = 0;
38 string8 **tokens = PushString(arena, buffer.size);
39
40 b32 FL = TRUE;
41
42 if(buffer.size < 0) return NULL;
43 for(s32 index = 0;
44 buffer.data[index] != '\0';
45 ++index)
46 {
47 csv_row *row = PushStruct(arena, csv_row);
48 token *tok = PushStruct(arena, token);
49
50 u8 point = buffer.data[index];
51
52 u8 *start = buffer.data;
53 u8 *end = NULL;
54
55 unused(row);
56
57 switch(point)
58 {
59 case('\n'):
60 {
61
62 if(FL)
63 {
64 FL = FALSE;
65 tok->flags |= END_FL;
66 }
67
68 break;
69
70 }
71
72 case(','):
73 {
74 end = start - 1;
75 break;
76 }
77
78 default:
79 {
80 printf("point: %c\n", point);
81 count++;
82 break;
83 }
84 }
85
86 token->lexeme = String8Cast(start, end - start);
87
88 *tokens = token;
89 ++tokens;
90
91
92 return NULL;
93 }
94}