zig fmt: deref, unwrap optional

This commit is contained in:
Asherah Connor 2021-02-04 21:33:41 +11:00 committed by Andrew Kelley
parent 725adf8332
commit 4428acf0f7
3 changed files with 19 additions and 24 deletions

View File

@ -462,6 +462,7 @@ pub const Tree = struct {
.UndefinedLiteral,
.UnreachableLiteral,
.Identifier,
.Deref,
=> return main_tokens[n] + end_offset,
.Call,
@ -515,7 +516,6 @@ pub const Tree = struct {
.Asm => unreachable, // TODO
.SliceOpen => unreachable, // TODO
.Slice => unreachable, // TODO
.Deref => unreachable, // TODO
.ArrayInitOne => unreachable, // TODO
.ArrayInit => unreachable, // TODO
.StructInitOne => unreachable, // TODO

View File

@ -1503,15 +1503,15 @@ test "zig fmt: top-level fields" {
// \\
// );
//}
//
//test "zig fmt: ptr deref operator and unwrap optional operator" {
// try testCanonical(
// \\const a = b.*;
// \\const a = b.?;
// \\
// );
//}
//
test "zig fmt: ptr deref operator and unwrap optional operator" {
try testCanonical(
\\const a = b.*;
\\const a = b.?;
\\
);
}
//test "zig fmt: comment after if before another if" {
// try testCanonical(
// \\test "aoeu" {

View File

@ -991,21 +991,16 @@ fn renderExpression(ais: *Ais, tree: ast.Tree, node: ast.Node.Index, space: Spac
// return renderToken(ais, tree, suffix_op.rtoken, space); // ]
//},
.Deref => unreachable, // TODO
//.Deref => {
// const suffix_op = base.castTag(.Deref).?;
.Deref => {
try renderExpression(ais, tree, datas[node].lhs, .None);
return renderToken(ais, tree, main_tokens[node], space);
},
// try renderExpression(ais, tree, suffix_op.lhs, Space.None);
// return renderToken(ais, tree, suffix_op.rtoken, space); // .*
//},
.UnwrapOptional => unreachable, // TODO
//.UnwrapOptional => {
// const suffix_op = base.castTag(.UnwrapOptional).?;
// try renderExpression(ais, tree, suffix_op.lhs, Space.None);
// try renderToken(ais, tree, tree.prevToken(suffix_op.rtoken), Space.None); // .
// return renderToken(ais, tree, suffix_op.rtoken, space); // ?
//},
.UnwrapOptional => {
try renderExpression(ais, tree, datas[node].lhs, .None);
try renderToken(ais, tree, main_tokens[node], .None);
return renderToken(ais, tree, datas[node].rhs, space);
},
.Break => unreachable, // TODO
//.Break => {