From bfbe26734d4167977fff0d675ff55c68d75dd3be Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Sun, 20 May 2018 14:50:27 -0400 Subject: [PATCH] zig fmt: add pointer deref syntax --- std/zig/parse.zig | 11 +++++++++++ std/zig/parser_test.zig | 7 +++++++ 2 files changed, 18 insertions(+) diff --git a/std/zig/parse.zig b/std/zig/parse.zig index f4e819e544..865ece6f5d 100644 --- a/std/zig/parse.zig +++ b/std/zig/parse.zig @@ -2195,6 +2195,17 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree { continue; }, Token.Id.Period => { + if (eatToken(&tok_it, &tree, Token.Id.Asterisk)) |asterisk_token| { + const node = try arena.construct(ast.Node.SuffixOp{ + .base = ast.Node{ .id = ast.Node.Id.SuffixOp }, + .lhs = lhs, + .op = ast.Node.SuffixOp.Op.Deref, + .rtoken = asterisk_token, + }); + opt_ctx.store(&node.base); + stack.append(State{ .SuffixOpExpressionEnd = opt_ctx.toRequired() }) catch unreachable; + continue; + } const node = try arena.construct(ast.Node.InfixOp{ .base = ast.Node{ .id = ast.Node.Id.InfixOp }, .lhs = lhs, diff --git a/std/zig/parser_test.zig b/std/zig/parser_test.zig index 094c4d51f7..63d56167e8 100644 --- a/std/zig/parser_test.zig +++ b/std/zig/parser_test.zig @@ -1,3 +1,10 @@ +test "zig fmt: ptr deref operator" { + try testCanonical( + \\const a = b.*; + \\ + ); +} + test "zig fmt: comment after if before another if" { try testCanonical( \\test "aoeu" {