summaryrefslogtreecommitdiff
path: root/source/lexer
diff options
context:
space:
mode:
authornasr <nsrddyn@gmail.com>2026-03-08 21:01:43 +0000
committernasr <nsrddyn@gmail.com>2026-03-08 21:01:43 +0000
commit71ced998122c357bc62e54d9bb4e124c88acf94b (patch)
tree746fca3d71a8640478ad6b6f4429a19f4dfbbda8 /source/lexer
parentf8f24f8c67fe903e267ab29bb2fbb9d334a722de (diff)
refactor(main): worked on string handling in C and other stuff
Diffstat (limited to 'source/lexer')
-rw-r--r--source/lexer/lexer.c100
-rw-r--r--source/lexer/lexer.h23
2 files changed, 0 insertions, 123 deletions
diff --git a/source/lexer/lexer.c b/source/lexer/lexer.c
deleted file mode 100644
index 948afd0..0000000
--- a/source/lexer/lexer.c
+++ /dev/null
@@ -1,100 +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, csv_table *global_table, mem_arena *arena)
36{
37 i32 count = 0;
38 string8 **tokens = PushArray(arena, string8 *, buffer.size / 10);
39 b32 first_line = 1;
40
41 if(buffer.size < 0) return NULL;
42 for(i32 index = 0;
43 buffer.data[index] != '\0';
44 ++index)
45 {
46 csv_row *row = PushStruct(arena, csv_row);
47 string8 token = {0};
48
49 u8 point = buffer.data[index];
50
51 u8 *start = buffer.data;
52 u8 *end = NULL;
53
54 unused(row);
55
56 switch (point)
57 {
58 case '\n':
59 {
60 first_line = -1;
61 break;
62 }
63 case ',':
64 {
65 end = start - 1;
66
67 if (first_line)
68 {
69 global_table->headers = &token;
70 ++global_table->headers;
71 break;
72 }
73 else
74 {
75
76 break;
77 }
78 }
79
80 default:
81 {
82 printf("point: %c\n", point);
83 count++;
84 break;
85 }
86 }
87
88 token = (string8){
89 .data = start,
90 .size = end - start,
91 };
92
93 **tokens = token;
94 ++*tokens;
95 }
96
97 printf("%d", count);
98
99 return NULL;
100}
diff --git a/source/lexer/lexer.h b/source/lexer/lexer.h
deleted file mode 100644
index 86f8427..0000000
--- a/source/lexer/lexer.h
+++ /dev/null
@@ -1,23 +0,0 @@
1#ifndef ENGINE_LEXER_H
2#define ENGINE_LEXER_H
3
4typedef enum token_type token_type;
5enum token_type
6{
7 // first 255 tokens for ascii characters
8 TOKEN_UNDEFINED = 255,
9 TOKEN_IDENTIFIER,
10 TOKEN_VALUE,
11
12};
13
14typedef struct token token;
15struct token
16{
17 string8 lexeme;
18 token_type type;
19
20};
21
22
23#endif /* ENGINE_LEXER_H */