aboutsummaryrefslogtreecommitdiff
path: root/src/parser.cpp
diff options
context:
space:
mode:
authorVexu <15308111+Vexu@users.noreply.github.com>2019-11-15 14:12:14 +0200
committerVexu <15308111+Vexu@users.noreply.github.com>2019-11-15 15:02:51 +0200
commite509d21f39af726da3c6001b0c20f2c765be07a5 (patch)
treeeff4c0f8081c81065a9bbf9d1ab0f4e3d7aec0ab /src/parser.cpp
parentb92f42d1f4b91bb343558f72af84ea052da4ac98 (diff)
downloadzig-e509d21f39af726da3c6001b0c20f2c765be07a5.tar.gz
zig-e509d21f39af726da3c6001b0c20f2c765be07a5.zip
implemented container doc comments in stage 1
Diffstat (limited to 'src/parser.cpp')
-rw-r--r--src/parser.cpp23
1 files changed, 22 insertions, 1 deletions
diff --git a/src/parser.cpp b/src/parser.cpp
index 484e145cfa..eef832e32c 100644
--- a/src/parser.cpp
+++ b/src/parser.cpp
@@ -493,6 +493,7 @@ static AstNode *ast_parse_root(ParseContext *pc) {
node->data.container_decl.layout = ContainerLayoutAuto;
node->data.container_decl.kind = ContainerKindStruct;
node->data.container_decl.is_root = true;
+ node->data.container_decl.doc_comments = members.doc_comments;
return node;
}
@@ -514,6 +515,21 @@ static Token *ast_parse_doc_comments(ParseContext *pc, Buf *buf) {
return first_doc_token;
}
+static void ast_parse_container_doc_comments(ParseContext *pc, Buf *buf) {
+ if (buf_len(buf) != 0 && peek_token(pc)->id == TokenIdContainerDocComment) {
+ buf_append_char(buf, '\n');
+ }
+ Token *doc_token = nullptr;
+ while ((doc_token = eat_token_if(pc, TokenIdContainerDocComment))) {
+ if (buf->list.length == 0) {
+ buf_resize(buf, 0);
+ }
+ // chops off '//!' but leaves '\n'
+ buf_append_mem(buf, buf_ptr(pc->buf) + doc_token->start_pos + 3,
+ doc_token->end_pos - doc_token->start_pos - 3);
+ }
+}
+
// ContainerMembers
// <- TestDecl ContainerMembers
// / TopLevelComptime ContainerMembers
@@ -523,7 +539,11 @@ static Token *ast_parse_doc_comments(ParseContext *pc, Buf *buf) {
// /
static AstNodeContainerDecl ast_parse_container_members(ParseContext *pc) {
AstNodeContainerDecl res = {};
+ Buf tld_doc_comment_buf = BUF_INIT;
+ buf_resize(&tld_doc_comment_buf, 0);
for (;;) {
+ ast_parse_container_doc_comments(pc, &tld_doc_comment_buf);
+
AstNode *test_decl = ast_parse_test_decl(pc);
if (test_decl != nullptr) {
res.decls.append(test_decl);
@@ -566,7 +586,7 @@ static AstNodeContainerDecl ast_parse_container_members(ParseContext *pc) {
break;
}
-
+ res.doc_comments = tld_doc_comment_buf;
return res;
}
@@ -2797,6 +2817,7 @@ static AstNode *ast_parse_container_decl_auto(ParseContext *pc) {
res->data.container_decl.fields = members.fields;
res->data.container_decl.decls = members.decls;
+ res->data.container_decl.doc_comments = members.doc_comments;
return res;
}