Fix parser logic for first comment group line in a file

This commit is contained in:
gingerBill
2020-11-17 15:45:55 +00:00
parent 7442f4bab6
commit 34ca4e92eb
2 changed files with 31 additions and 11 deletions

View File

@@ -1193,6 +1193,12 @@ CommentGroup *consume_comment_group(AstFile *f, isize n, isize *end_line_) {
Array<Token> list = {};
list.allocator = heap_allocator();
isize end_line = f->curr_token.pos.line;
if (f->curr_token_index == 1 &&
f->prev_token.kind == Token_Comment &&
f->prev_token.pos.line+1 == f->curr_token.pos.line) {
// NOTE(bill): Special logic for the first comment in the file
array_add(&list, f->prev_token);
}
while (f->curr_token.kind == Token_Comment &&
f->curr_token.pos.line <= end_line+n) {
array_add(&list, consume_comment(f, &end_line));