From 462ae1584bd0ae92e531aa84be85acef940e2bd0 Mon Sep 17 00:00:00 2001 From: Ashley Coleman Date: Thu, 29 Aug 2024 11:57:52 -0600 Subject: [PATCH] format: Fix bad formatting with mixed or pipes (#1639) * format: Fix bad formatting with mixed or pipes * format --- tests/wake-format/basic/basic.wake | 1 + tests/wake-format/basic/stdout | 7 +++++++ tools/wake-format/emitter.cpp | 6 ++++-- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/tests/wake-format/basic/basic.wake b/tests/wake-format/basic/basic.wake index cffaf53f6..d88e5bca7 100644 --- a/tests/wake-format/basic/basic.wake +++ b/tests/wake-format/basic/basic.wake @@ -1498,3 +1498,4 @@ def a = a |> b |> c def a = a |< b |< c def a = a |> b |< c def a = a |< b |> c +def a = a | b |> c | c |< d diff --git a/tests/wake-format/basic/stdout b/tests/wake-format/basic/stdout index 2a960c331..068ec1551 100644 --- a/tests/wake-format/basic/stdout +++ b/tests/wake-format/basic/stdout @@ -1802,3 +1802,10 @@ def a = a |< b |> c + +def a = + a + | b + |> c + | c + |< d diff --git a/tools/wake-format/emitter.cpp b/tools/wake-format/emitter.cpp index a3aebd186..fca1aa101 100644 --- a/tools/wake-format/emitter.cpp +++ b/tools/wake-format/emitter.cpp @@ -1389,8 +1389,10 @@ wcl::doc Emitter::walk_binary(ctx_t ctx, CSTElement node) { std::vector parts = {}; if (is_op_left_assoc(op_token)) { if (is_binop_matching_str(op_token, TOKEN_OP_OR, "|>") || - is_binop_matching_str(op_token, TOKEN_OP_OR, "|<")) { - parts = collect_left_binary({{TOKEN_OP_OR, "|>"}, {TOKEN_OP_OR, "|<"}}, node); + is_binop_matching_str(op_token, TOKEN_OP_OR, "|<") || + is_binop_matching_str(op_token, TOKEN_OP_OR, "|")) { + parts = + collect_left_binary({{TOKEN_OP_OR, "|>"}, {TOKEN_OP_OR, "|<"}, {TOKEN_OP_OR, "|"}}, node); } else { parts = collect_left_binary({{op_token.id(), op_token.fragment().segment().str()}}, node); }