diff options
| author | Shritesh Bhattarai <shritesh@shritesh.com> | 2019-04-05 11:25:32 -0500 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2019-04-05 12:27:13 -0400 |
| commit | 2f236e6efb2c95d086b916334db492b948b48e44 (patch) | |
| tree | 4bc323bb56201ea179b5827bce7679324a595582 /std | |
| parent | 6cc2d3938e81f1c5db9cf94db90fda11b026422a (diff) | |
| download | zig-2f236e6efb2c95d086b916334db492b948b48e44.tar.gz zig-2f236e6efb2c95d086b916334db492b948b48e44.zip | |
fmt: support trailing comma after var_args
Diffstat (limited to 'std')
| -rw-r--r-- | std/zig/parse.zig | 16 | ||||
| -rw-r--r-- | std/zig/parser_test.zig | 9 |
2 files changed, 23 insertions, 2 deletions
diff --git a/std/zig/parse.zig b/std/zig/parse.zig index 5214a0575b..96aec714ab 100644 --- a/std/zig/parse.zig +++ b/std/zig/parse.zig @@ -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 }); diff --git a/std/zig/parser_test.zig b/std/zig/parser_test.zig index 10434c8aa2..4349699482 100644 --- a/std/zig/parser_test.zig +++ b/std/zig/parser_test.zig @@ -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}; |
