diff options
Diffstat (limited to 'source/lexer.c')
| -rw-r--r-- | source/lexer.c | 44 |
1 files changed, 15 insertions, 29 deletions
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) | |||
| 34 | internal token * | 34 | internal token * |
| 35 | tokenize_csv(string8 buffer, mem_arena *arena) | 35 | tokenize_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 | } |
