fmt: support trailing comma after var_args

This commit is contained in:
Shritesh Bhattarai 2019-04-05 11:25:32 -05:00 committed by Andrew Kelley
parent 6cc2d3938e
commit 2f236e6efb
2 changed files with 23 additions and 2 deletions

View File

@ -903,8 +903,20 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
State.ParamDeclEnd => |ctx| {
if (eatToken(&tok_it, &tree, Token.Id.Ellipsis3)) |ellipsis3| {
ctx.param_decl.var_args_token = ellipsis3;
stack.append(State{ .ExpectToken = Token.Id.RParen }) catch unreachable;
continue;
switch (expectCommaOrEnd(&tok_it, &tree, Token.Id.RParen)) {
ExpectCommaOrEndResult.end_token => |t| {
if (t == null) {
stack.append(State{ .ExpectToken = Token.Id.RParen }) catch unreachable;
continue;
}
continue;
},
ExpectCommaOrEndResult.parse_error => |e| {
try tree.errors.push(e);
return tree;
},
}
}
try stack.append(State{ .ParamDeclComma = ctx.fn_proto });

View File

@ -354,6 +354,15 @@ test "zig fmt: fn decl with trailing comma" {
);
}
test "zig fmt: var_args with trailing comma" {
try testCanonical(
\\pub fn add(
\\ a: ...,
\\) void {}
\\
);
}
test "zig fmt: enum decl with no trailing comma" {
try testTransform(
\\const StrLitKind = enum {Normal, C};