fix zig fmt of c pointers

This commit is contained in:
Vexu 2019-12-05 14:45:36 +02:00
parent bef3769bb7
commit 10cc8cad86
No known key found for this signature in database
GPG Key ID: 59AEB8936E16A6AC
3 changed files with 14 additions and 4 deletions

View File

@ -2558,7 +2558,7 @@ fn parsePtrTypeStart(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node
_ = try expectToken(it, tree, .RBracket);
const node = try arena.create(Node.PrefixOp);
node.* = .{
.op_token = ident,
.op_token = lbracket,
.op = .{ .PtrType = .{} },
.rhs = undefined, // set by caller
};

View File

@ -1,3 +1,10 @@
test "zig fmt: c pointer type" {
try testCanonical(
\\pub extern fn repro() [*c]const u8;
\\
);
}
test "zig fmt: asm expression with comptime content" {
try testCanonical(
\\comptime {
@ -21,6 +28,7 @@ test "zig fmt: asm expression with comptime content" {
\\
);
}
test "zig fmt: var struct field" {
try testCanonical(
\\pub const Pointer = struct {

View File

@ -421,8 +421,10 @@ fn renderExpression(
const op_tok_id = tree.tokens.at(prefix_op_node.op_token).id;
switch (op_tok_id) {
.Asterisk, .AsteriskAsterisk => try stream.writeByte('*'),
.Identifier => try stream.write("[*c]"),
.LBracket => try stream.write("[*"),
.LBracket => if (tree.tokens.at(prefix_op_node.op_token + 2).id == .Identifier)
try stream.write("[*c")
else
try stream.write("[*"),
else => unreachable,
}
if (ptr_info.sentinel) |sentinel| {
@ -435,7 +437,7 @@ fn renderExpression(
try renderExpression(allocator, stream, tree, indent, start_col, sentinel, sentinel_space);
}
switch (op_tok_id) {
.Asterisk, .AsteriskAsterisk, .Identifier => {},
.Asterisk, .AsteriskAsterisk => {},
.LBracket => try stream.writeByte(']'),
else => unreachable,
}