Skip to content

Commit

Permalink
format: Fix bad formatting with mixed or pipes (#1639)
Browse files Browse the repository at this point in the history
* format: Fix bad formatting with mixed or pipes

* format
  • Loading branch information
V-FEXrt authored Aug 29, 2024
1 parent ae9647d commit 462ae15
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
1 change: 1 addition & 0 deletions tests/wake-format/basic/basic.wake
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 7 additions & 0 deletions tests/wake-format/basic/stdout
Original file line number Diff line number Diff line change
Expand Up @@ -1802,3 +1802,10 @@ def a =
a
|< b
|> c

def a =
a
| b
|> c
| c
|< d
6 changes: 4 additions & 2 deletions tools/wake-format/emitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1389,8 +1389,10 @@ wcl::doc Emitter::walk_binary(ctx_t ctx, CSTElement node) {
std::vector<CSTElement> 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);
}
Expand Down

0 comments on commit 462ae15

Please sign in to comment.