summaryrefslogtreecommitdiff
path: root/source/lexer.c
diff options
context:
space:
mode:
Diffstat (limited to 'source/lexer.c')
-rw-r--r--source/lexer.c80
1 files changed, 0 insertions, 80 deletions
diff --git a/source/lexer.c b/source/lexer.c
deleted file mode 100644
index decfb7a..0000000
--- a/source/lexer.c
+++ /dev/null
@@ -1,80 +0,0 @@
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
38 b32 FL = TRUE;
39
40 if(buffer.size < 0) return NULL;
41 for(s32 index = 0; buffer.data[index] != '\0'; ++index)
42 {
43 token *tok = PushStruct(arena, token);
44 u8 point = buffer.data[index];
45
46 s32 start = 0;
47 s32 end = 0;
48
49 if(is_whitespace(point))
50 {
51 print("csv file is invalid");
52 return NULL;
53 }
54
55 switch(point)
56 {
57 case('\n'):
58 {
59 if(FL) tok->flags |= END_FL;
60 break;
61 }
62
63 case(','):
64 {
65 end = index - 1;
66 start = index + 1;
67 break;
68 }
69 default:
70 {
71 break;
72 }
73 }
74
75 tok->lexeme = String8Cast(&buffer.data[start], end - start);
76 tok->next = tok;
77 }
78
79 return NULL;
80}