mirror of
https://github.com/Ed94/Odin.git
synced 2026-07-31 03:40:08 +00:00
Fix parser logic for first comment group line in a file
This commit is contained in:
+25
-11
@@ -110,20 +110,23 @@ void print_doc_line_no_newline(i32 indent, char const *fmt, ...) {
|
|||||||
va_end(va);
|
va_end(va);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool print_doc_comment_group_string(i32 indent, CommentGroup const &g) {
|
bool print_doc_comment_group_string(i32 indent, CommentGroup *g) {
|
||||||
|
if (g == nullptr) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
isize len = 0;
|
isize len = 0;
|
||||||
for_array(i, g.list) {
|
for_array(i, g->list) {
|
||||||
String comment = g.list[i].string;
|
String comment = g->list[i].string;
|
||||||
len += comment.len;
|
len += comment.len;
|
||||||
len += 1; // for \n
|
len += 1; // for \n
|
||||||
}
|
}
|
||||||
if (len == 0) {
|
if (len <= g->list.count) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
isize count = 0;
|
isize count = 0;
|
||||||
for_array(i, g.list) {
|
for_array(i, g->list) {
|
||||||
String comment = g.list[i].string;
|
String comment = g->list[i].string;
|
||||||
if (comment[1] == '/') {
|
if (comment[1] == '/') {
|
||||||
comment.text += 2;
|
comment.text += 2;
|
||||||
comment.len -= 2;
|
comment.len -= 2;
|
||||||
@@ -131,7 +134,11 @@ bool print_doc_comment_group_string(i32 indent, CommentGroup const &g) {
|
|||||||
comment.text += 2;
|
comment.text += 2;
|
||||||
comment.len -= 4;
|
comment.len -= 4;
|
||||||
}
|
}
|
||||||
comment = string_trim_whitespace(comment);
|
if (comment.len > 0 && comment[0] == ' ') {
|
||||||
|
comment.text += 1;
|
||||||
|
comment.len -= 1;
|
||||||
|
}
|
||||||
|
|
||||||
if (string_starts_with(comment, str_lit("@("))) {
|
if (string_starts_with(comment, str_lit("@("))) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -164,6 +171,15 @@ void print_doc_package(CheckerInfo *info, AstPackage *pkg) {
|
|||||||
|
|
||||||
print_doc_line(0, "package %.*s", LIT(pkg->name));
|
print_doc_line(0, "package %.*s", LIT(pkg->name));
|
||||||
|
|
||||||
|
|
||||||
|
for_array(i, pkg->files) {
|
||||||
|
AstFile *f = pkg->files[i];
|
||||||
|
if (f->pkg_decl) {
|
||||||
|
GB_ASSERT(f->pkg_decl->kind == Ast_PackageDecl);
|
||||||
|
print_doc_comment_group_string(1, f->pkg_decl->PackageDecl.docs);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (pkg->scope != nullptr) {
|
if (pkg->scope != nullptr) {
|
||||||
auto entities = array_make<Entity *>(heap_allocator(), 0, pkg->scope->elements.entries.count);
|
auto entities = array_make<Entity *>(heap_allocator(), 0, pkg->scope->elements.entries.count);
|
||||||
defer (array_free(&entities));
|
defer (array_free(&entities));
|
||||||
@@ -244,10 +260,8 @@ void print_doc_package(CheckerInfo *info, AstPackage *pkg) {
|
|||||||
if (comment) {
|
if (comment) {
|
||||||
// gb_printf(" <comment>");
|
// gb_printf(" <comment>");
|
||||||
}
|
}
|
||||||
if (docs) {
|
if (print_doc_comment_group_string(3, docs)) {
|
||||||
if (print_doc_comment_group_string(3, *docs)) {
|
gb_printf("\n");
|
||||||
gb_printf("\n");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1193,6 +1193,12 @@ CommentGroup *consume_comment_group(AstFile *f, isize n, isize *end_line_) {
|
|||||||
Array<Token> list = {};
|
Array<Token> list = {};
|
||||||
list.allocator = heap_allocator();
|
list.allocator = heap_allocator();
|
||||||
isize end_line = f->curr_token.pos.line;
|
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 &&
|
while (f->curr_token.kind == Token_Comment &&
|
||||||
f->curr_token.pos.line <= end_line+n) {
|
f->curr_token.pos.line <= end_line+n) {
|
||||||
array_add(&list, consume_comment(f, &end_line));
|
array_add(&list, consume_comment(f, &end_line));
|
||||||
|
|||||||
Reference in New Issue
Block a user