authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-03-30 19:22:28-04:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2019-03-30 19:22:28-04:00
log90a78866db5488ceae584e32287acb9f2461d945
tree5ded749853638808e009c467b9ff770b4c2c5736
parent5703ab1d0c68394f346673dc715c05813a6c4df1
parentb0d89cfe3fdd1139a194a1765460e11e6c34b45b
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

Merge pull request #2112 from shritesh/param_decl_doc_comments

Add doc_comments to param decl

4 files changed, 27 insertions(+), 1 deletions(-)

std/zig/ast.zig+1
......@@ -940,6 +940,7 @@ pub const Node = struct {
940940
941941 pub const ParamDecl = struct {
942942 base: Node,
943 doc_comments: ?*DocComment,
943944 comptime_token: ?TokenIndex,
944945 noalias_token: ?TokenIndex,
945946 name_token: ?TokenIndex,
std/zig/parse.zig+2
......@@ -854,12 +854,14 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
854854 },
855855
856856 State.ParamDecl => |fn_proto| {
857 const comments = try eatDocComments(arena, &tok_it, &tree);
857858 if (eatToken(&tok_it, &tree, Token.Id.RParen)) |_| {
858859 continue;
859860 }
860861 const param_decl = try arena.create(ast.Node.ParamDecl);
861862 param_decl.* = ast.Node.ParamDecl{
862863 .base = ast.Node{ .id = ast.Node.Id.ParamDecl },
864 .doc_comments = comments,
863865 .comptime_token = null,
864866 .noalias_token = null,
865867 .name_token = null,
std/zig/parser_test.zig+21
......@@ -75,6 +75,27 @@ test "zig fmt: correctly move doc comments on struct fields" {
7575 );
7676}
7777
78test "zig fmt: doc comments on param decl" {
79 try testCanonical(
80 \\pub const Allocator = struct {
81 \\ shrinkFn: fn (
82 \\ self: *Allocator,
83 \\ /// Guaranteed to be the same as what was returned from most recent call to
84 \\ /// `allocFn`, `reallocFn`, or `shrinkFn`.
85 \\ old_mem: []u8,
86 \\ /// Guaranteed to be the same as what was returned from most recent call to
87 \\ /// `allocFn`, `reallocFn`, or `shrinkFn`.
88 \\ old_alignment: u29,
89 \\ /// Guaranteed to be less than or equal to `old_mem.len`.
90 \\ new_byte_count: usize,
91 \\ /// Guaranteed to be less than or equal to `old_alignment`.
92 \\ new_alignment: u29,
93 \\ ) []u8,
94 \\};
95 \\
96 );
97}
98
7899test "zig fmt: preserve space between async fn definitions" {
79100 try testCanonical(
80101 \\async fn a() void {}
std/zig/render.zig+3-1
......@@ -1137,7 +1137,7 @@ fn renderExpression(
11371137 var it = fn_proto.params.iterator(0);
11381138 while (it.next()) |param_decl_node| {
11391139 try stream.writeByteNTimes(' ', new_indent);
1140 try renderParamDecl(allocator, stream, tree, indent, start_col, param_decl_node.*, Space.Comma);
1140 try renderParamDecl(allocator, stream, tree, new_indent, start_col, param_decl_node.*, Space.Comma);
11411141 }
11421142 try stream.writeByteNTimes(' ', indent);
11431143 }
......@@ -1779,6 +1779,8 @@ fn renderParamDecl(
17791779) (@typeOf(stream).Child.Error || Error)!void {
17801780 const param_decl = @fieldParentPtr(ast.Node.ParamDecl, "base", base);
17811781
1782 try renderDocComments(tree, stream, param_decl, indent, start_col);
1783
17821784 if (param_decl.comptime_token) |comptime_token| {
17831785 try renderToken(tree, stream, comptime_token, indent, start_col, Space.Space);
17841786 }