diff options
Diffstat (limited to 'source/lexer/lexer.c')
| -rw-r--r-- | source/lexer/lexer.c | 100 |
1 files changed, 0 insertions, 100 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 | ||
| 4 | internal b32 | ||
| 5 | is_alpha(u8 point) | ||
| 6 | { | ||
| 7 | return ((point >= 'a' && point <= 'z') || (point >= 'A' && point <= 'Z') || (point == '_')); | ||
| 8 | } | ||
| 9 | |||
| 10 | internal b32 | ||
| 11 | is_digit(u8 point) | ||
| 12 | { | ||
| 13 | return (point >= '0' && point <= '9'); | ||
| 14 | } | ||
| 15 | |||
| 16 | internal b32 | ||
| 17 | is_alpha_num(u8 point) | ||
| 18 | { | ||
| 19 | return (is_alpha(point) || is_digit(point)); | ||
| 20 | } | ||
| 21 | |||
| 22 | internal b32 | ||
| 23 | is_whitespace(u8 point) | ||
| 24 | { | ||
| 25 | return (point == '\n' || point == '\r' || point == ' ' || point == '\t'); | ||
| 26 | } | ||
| 27 | |||
| 28 | internal b32 | ||
| 29 | is_delimiter(u8 point) | ||
| 30 | { | ||
| 31 | return (point == ','); | ||
| 32 | } | ||
| 33 | |||
| 34 | internal token * | ||
| 35 | tokenize_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 | } | ||
