Skip to content

Commit

Permalink
format: Fixup failing cases (#1210)
Browse files Browse the repository at this point in the history
* Fixup failing cases
* address comments
  • Loading branch information
V-FEXrt authored Apr 19, 2023
1 parent f2ef66f commit 69fcfef
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 14 deletions.
4 changes: 4 additions & 0 deletions tests/wake-format/basic/basic.wake
Original file line number Diff line number Diff line change
Expand Up @@ -620,12 +620,16 @@ global export data Let =

def x + y = add x y

export def (argument: a) | (pipeFn: a => b): b =
pipeFn argument

def tool (dir: String) (addHeaders: String) (addHeaders: String) (addHeaders: String) (addHeaders: String) (addHeaders: String) (addHeaders: String) (addHeaders: String) (addHeaders: String) (addHeaders: String) (addHeaders: String) =
""

def tool (dir: String) (addHeaders: String) (addHeaders: String) (addHeaders: String) (addHeaders: String) (addHeaders: String) (addHeaders: String) (addHeaders: String) (addHeaders: String) (addHeaders: String) (addHeaders: String) = ""

def Pair _ _: Pair Integer String = Pair 44 "as"
def Pair _ _ : Pair Integer String = Pair 44 "as"

def f0 = match _ _
(x: Integer) (True: Boolean) = x+1
Expand Down
5 changes: 5 additions & 0 deletions tests/wake-format/basic/stdout
Original file line number Diff line number Diff line change
Expand Up @@ -764,10 +764,15 @@ global export data Let =
def x + y =
add x y

export def (argument: a) | (pipeFn: a => b): b = pipeFn argument

def tool (dir: String) (addHeaders: String) (addHeaders: String) (addHeaders: String) (addHeaders: String) (addHeaders: String) (addHeaders: String) (addHeaders: String) (addHeaders: String) (addHeaders: String) (addHeaders: String) = ""

def tool (dir: String) (addHeaders: String) (addHeaders: String) (addHeaders: String) (addHeaders: String) (addHeaders: String) (addHeaders: String) (addHeaders: String) (addHeaders: String) (addHeaders: String) (addHeaders: String) = ""

def Pair _ _: Pair Integer String =
Pair 44 "as"

def Pair _ _: Pair Integer String =
Pair 44 "as"

Expand Down
23 changes: 9 additions & 14 deletions tools/wake-format/emitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,18 +114,6 @@ static inline bool is_simple_literal(wcl::doc_builder& builder, ctx_t ctx, CSTEl
return part.empty();
}

static inline bool contains_req_else(wcl::doc_builder& builder, ctx_t ctx, CSTElement& node,
const token_traits_map_t& traits) {
CSTElement copy = node;
while (!copy.empty()) {
if (copy.id() == CST_REQ_ELSE) {
return true;
}
copy.nextSiblingElement();
}
return false;
}

static bool compare_doc_height(const wcl::doc& lhs, const wcl::doc& rhs) {
return lhs->height() < rhs->height();
}
Expand Down Expand Up @@ -255,10 +243,8 @@ static size_t count_allowed_newlines(const token_traits_map_t& traits,
static wcl::doc select_best_choice(std::vector<wcl::optional<wcl::doc>> choices) {
std::vector<wcl::doc> lte_fmt = {};
std::vector<wcl::doc> gt_fmt = {};
int i = 0;

for (auto choice_opt : choices) {
i++;
if (!choice_opt) {
continue;
}
Expand Down Expand Up @@ -1130,6 +1116,7 @@ wcl::doc Emitter::walk_ascribe(ctx_t ctx, CSTElement node) {
MEMO(ctx, node);
MEMO_RET(fmt()
.walk(WALK_NODE)
.consume_wsnlc()
.token(TOKEN_P_ASCRIBE)
.ws()
.walk(WALK_NODE)
Expand Down Expand Up @@ -1263,6 +1250,14 @@ wcl::doc Emitter::walk_binary(ctx_t ctx, CSTElement node) {
parts = collect_right_binary(op_token, node);
}

if (ctx.explode_option == ExplodeOption::Prevent) {
auto doc = combine_flat(op_token, ctx.binop(), parts);
if (!doc) {
FMT_ASSERT(false, op_token, "Failed to flat format binop");
}
MEMO_RET(*doc);
}

if (!ctx.nested_binop && (is_binop_matching_str(op_token, TOKEN_OP_DOLLAR, "$") ||
is_binop_matching_str(op_token, TOKEN_OP_OR, "|"))) {
MEMO_RET(select_best_choice({
Expand Down

0 comments on commit 69fcfef

Please sign in to comment.