authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-05-20 14:50:27-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-05-20 14:50:27-04:00
logbfbe26734d4167977fff0d675ff55c68d75dd3be
tree00e70f00e79175702b28b6896cf436af01c00a26
parent83a78094788038fcf487e5947945a1f5900d564a

zig fmt: add pointer deref syntax


2 files changed, 18 insertions(+), 0 deletions(-)

std/zig/parse.zig+11
...@@ -2195,6 +2195,17 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {...@@ -2195,6 +2195,17 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
2195 continue;2195 continue;
2196 },2196 },
2197 Token.Id.Period => {2197 Token.Id.Period => {
2198 if (eatToken(&tok_it, &tree, Token.Id.Asterisk)) |asterisk_token| {
2199 const node = try arena.construct(ast.Node.SuffixOp{
2200 .base = ast.Node{ .id = ast.Node.Id.SuffixOp },
2201 .lhs = lhs,
2202 .op = ast.Node.SuffixOp.Op.Deref,
2203 .rtoken = asterisk_token,
2204 });
2205 opt_ctx.store(&node.base);
2206 stack.append(State{ .SuffixOpExpressionEnd = opt_ctx.toRequired() }) catch unreachable;
2207 continue;
2208 }
2198 const node = try arena.construct(ast.Node.InfixOp{2209 const node = try arena.construct(ast.Node.InfixOp{
2199 .base = ast.Node{ .id = ast.Node.Id.InfixOp },2210 .base = ast.Node{ .id = ast.Node.Id.InfixOp },
2200 .lhs = lhs,2211 .lhs = lhs,
std/zig/parser_test.zig+7
...@@ -1,3 +1,10 @@...@@ -1,3 +1,10 @@
1test "zig fmt: ptr deref operator" {
2 try testCanonical(
3 \\const a = b.*;
4 \\
5 );
6}
7
1test "zig fmt: comment after if before another if" {8test "zig fmt: comment after if before another if" {
2 try testCanonical(9 try testCanonical(
3 \\test "aoeu" {10 \\test "aoeu" {