diff --git a/lexer.c b/lexer.c index b87bc96..b0e9d86 100644 --- a/lexer.c +++ b/lexer.c @@ -335,12 +335,20 @@ static void parse(lexer *l) continue; } + usize head = l->index; + + if (c == '/' && l->source[l->index+1] == '/') { + while (l->source[l->index] != '\n') { + l->index += 1; + } + l->column += (l->index - head - 1); + } + if (isspace(c)) { l->index += 1; continue; } - usize head = l->index; if (parse_special(l)) { l->column += (l->index - head - 1); @@ -383,6 +391,9 @@ lexer *lexer_init(char *source, usize size, arena *arena) lex->source = source; keywords = arena_alloc(arena, sizeof(trie_node)); + trie_insert(keywords, lex->allocator, "struct", TOKEN_STRUCT); + trie_insert(keywords, lex->allocator, "enum", TOKEN_ENUM); + trie_insert(keywords, lex->allocator, "union", TOKEN_UNION); trie_insert(keywords, lex->allocator, "while", TOKEN_WHILE); trie_insert(keywords, lex->allocator, "for", TOKEN_FOR); trie_insert(keywords, lex->allocator, "goto", TOKEN_GOTO); diff --git a/lexer.h b/lexer.h index 04961f8..c27bdd7 100644 --- a/lexer.h +++ b/lexer.h @@ -71,7 +71,11 @@ typedef enum { TOKEN_STATIC, TOKEN_CONST, TOKEN_EXTERN, - TOKEN_VOLATILE + TOKEN_VOLATILE, + + TOKEN_STRUCT, + TOKEN_ENUM, + TOKEN_UNION } token_type; typedef struct _token {