mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-06 23:58:50 +00:00
Barebones layout for the documentation declarations
This commit is contained in:
+79
-14
@@ -2,20 +2,21 @@
|
|||||||
|
|
||||||
gbString expr_to_string(AstNode *expression);
|
gbString expr_to_string(AstNode *expression);
|
||||||
|
|
||||||
void print_declaration(Parser *parser, AstNode *decl) {
|
String alloc_comment_group_string(gbAllocator a, CommentGroup g) {
|
||||||
switch (decl->kind) {
|
isize len = 0;
|
||||||
case_ast_node(pd, ProcDecl, decl);
|
for_array(i, g.list) {
|
||||||
GB_ASSERT(pd->name->kind == AstNode_Ident);
|
String comment = g.list[i].string;
|
||||||
String name = pd->name->Ident.string;
|
len += comment.len;
|
||||||
if (name.len == 0) {
|
len += 1; // for \n
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
if (name[0] == '_') {
|
if (len == 0) {
|
||||||
break;
|
return make_string(NULL, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
for_array(i, pd->docs.list) {
|
u8 *text = gb_alloc_array(a, u8, len+1);
|
||||||
String comment = pd->docs.list[i].string;
|
len = 0;
|
||||||
|
for_array(i, g.list) {
|
||||||
|
String comment = g.list[i].string;
|
||||||
if (comment[1] == '/') {
|
if (comment[1] == '/') {
|
||||||
comment.text += 2;
|
comment.text += 2;
|
||||||
comment.len -= 2;
|
comment.len -= 2;
|
||||||
@@ -24,8 +25,43 @@ void print_declaration(Parser *parser, AstNode *decl) {
|
|||||||
comment.len -= 4;
|
comment.len -= 4;
|
||||||
}
|
}
|
||||||
comment = string_trim_whitespace(comment);
|
comment = string_trim_whitespace(comment);
|
||||||
|
gb_memmove(text+len, comment.text, comment.len);
|
||||||
|
len += comment.len;
|
||||||
|
text[len++] = '\n';
|
||||||
|
}
|
||||||
|
return make_string(text, len);
|
||||||
|
}
|
||||||
|
|
||||||
gb_printf("%.*s\n", LIT(comment));
|
void print_type_spec(AstNode *spec) {
|
||||||
|
ast_node(ts, TypeSpec, spec);
|
||||||
|
GB_ASSERT(ts->name->kind == AstNode_Ident);
|
||||||
|
String name = ts->name->Ident.string;
|
||||||
|
if (name.len == 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (name[0] == '_') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
gb_printf("type %.*s\n", LIT(name));
|
||||||
|
}
|
||||||
|
|
||||||
|
void print_proc_decl(AstNodeProcDecl *pd) {
|
||||||
|
GB_ASSERT(pd->name->kind == AstNode_Ident);
|
||||||
|
String name = pd->name->Ident.string;
|
||||||
|
if (name.len == 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (name[0] == '_') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
String docs = alloc_comment_group_string(heap_allocator(), pd->docs);
|
||||||
|
defer (gb_free(heap_allocator(), docs.text));
|
||||||
|
|
||||||
|
if (docs.len > 0) {
|
||||||
|
gb_file_write(&gb__std_files[gbFileStandard_Output], docs.text, docs.len);
|
||||||
|
} else {
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ast_node(proc_type, ProcType, pd->type);
|
ast_node(proc_type, ProcType, pd->type);
|
||||||
@@ -50,9 +86,38 @@ void print_declaration(Parser *parser, AstNode *decl) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
gb_printf("\n\n");
|
gb_printf("\n\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
void print_declaration(AstNode *decl) {
|
||||||
|
switch (decl->kind) {
|
||||||
|
case_ast_node(gd, GenDecl, decl);
|
||||||
|
for_array(spec_index, gd->specs) {
|
||||||
|
AstNode *spec = gd->specs[spec_index];
|
||||||
|
switch(gd->token.kind) {
|
||||||
|
case Token_var:
|
||||||
|
case Token_let:
|
||||||
|
break;
|
||||||
|
case Token_const:
|
||||||
|
break;
|
||||||
|
case Token_type:
|
||||||
|
// print_type_spec(spec);
|
||||||
|
break;
|
||||||
|
case Token_import:
|
||||||
|
case Token_import_load:
|
||||||
|
break;
|
||||||
|
case Token_foreign_library:
|
||||||
|
case Token_foreign_system_library:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
case_end;
|
case_end;
|
||||||
|
|
||||||
case_ast_node(gd, GenDecl, decl);
|
case_ast_node(pd, ProcDecl, decl);
|
||||||
|
print_proc_decl(pd);
|
||||||
|
case_end;
|
||||||
|
|
||||||
|
case_ast_node(fb, ForeignBlockDecl, decl);
|
||||||
|
// TODO(bill)
|
||||||
case_end;
|
case_end;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -66,7 +131,7 @@ void generate_documentation(Parser *parser) {
|
|||||||
|
|
||||||
for_array(decl_index, file->decls) {
|
for_array(decl_index, file->decls) {
|
||||||
AstNode *decl = file->decls[decl_index];
|
AstNode *decl = file->decls[decl_index];
|
||||||
print_declaration(parser, decl);
|
print_declaration(decl);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user