added comment parsing

This commit is contained in:
Lorenzo Torres 2025-11-30 16:06:32 +01:00
parent c0f1b74a48
commit 038930d881
2 changed files with 17 additions and 2 deletions

13
lexer.c
View file

@ -335,12 +335,20 @@ static void parse(lexer *l)
continue; 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)) { if (isspace(c)) {
l->index += 1; l->index += 1;
continue; continue;
} }
usize head = l->index;
if (parse_special(l)) { if (parse_special(l)) {
l->column += (l->index - head - 1); l->column += (l->index - head - 1);
@ -383,6 +391,9 @@ lexer *lexer_init(char *source, usize size, arena *arena)
lex->source = source; lex->source = source;
keywords = arena_alloc(arena, sizeof(trie_node)); 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, "while", TOKEN_WHILE);
trie_insert(keywords, lex->allocator, "for", TOKEN_FOR); trie_insert(keywords, lex->allocator, "for", TOKEN_FOR);
trie_insert(keywords, lex->allocator, "goto", TOKEN_GOTO); trie_insert(keywords, lex->allocator, "goto", TOKEN_GOTO);

View file

@ -71,7 +71,11 @@ typedef enum {
TOKEN_STATIC, TOKEN_STATIC,
TOKEN_CONST, TOKEN_CONST,
TOKEN_EXTERN, TOKEN_EXTERN,
TOKEN_VOLATILE TOKEN_VOLATILE,
TOKEN_STRUCT,
TOKEN_ENUM,
TOKEN_UNION
} token_type; } token_type;
typedef struct _token { typedef struct _token {