added comment parsing
This commit is contained in:
parent
c0f1b74a48
commit
038930d881
2 changed files with 17 additions and 2 deletions
13
lexer.c
13
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);
|
||||
|
|
|
|||
6
lexer.h
6
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 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue