zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit 4428acf0f7b4b8da2709bffe1c304df435d89eed (tree)
parent 725adf833289e0a1b0826c6a774cea5283cec744
Author: Asherah Connor <ashe@kivikakk.ee>
Date:   Thu,  4 Feb 2021 21:33:41 +1100

zig fmt: deref, unwrap optional

Diffstat:
Mlib/std/zig/ast.zig | 2+-
Mlib/std/zig/parser_test.zig | 18+++++++++---------
Mlib/std/zig/render.zig | 23+++++++++--------------
3 files changed, 19 insertions(+), 24 deletions(-)

diff --git a/lib/std/zig/ast.zig b/lib/std/zig/ast.zig @@ -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 diff --git a/lib/std/zig/parser_test.zig b/lib/std/zig/parser_test.zig @@ -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" { diff --git a/lib/std/zig/render.zig b/lib/std/zig/render.zig @@ -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).?; - - // 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).?; + .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); - // 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 => {