Skip to content

Commit

Permalink
rework function param printing
Browse files Browse the repository at this point in the history
  • Loading branch information
phated committed Sep 30, 2023
1 parent 15e4e29 commit 7e75cbc
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 38 deletions.
2 changes: 1 addition & 1 deletion compiler/src/formatting/doc.re
Original file line number Diff line number Diff line change
Expand Up @@ -790,7 +790,7 @@ let concat_map = (~sep, ~lead=first => empty, ~trail=last => empty, ~f, l) => {
};
};

let parens = d => parens(nest(softline ++ d ++ softline));
let parens = d => parens(nest_all(softline ++ d ++ softline));
let parens_all = d => parens(nest_all(softline ++ d ++ softline));
let angle_brackets = d =>
angle_brackets(nest_all(softline ++ d ++ softline));
Expand Down
14 changes: 3 additions & 11 deletions compiler/src/formatting/format.re
Original file line number Diff line number Diff line change
Expand Up @@ -682,21 +682,13 @@ and print_expression = (expr: Parsetree.expression) => {
parens(
concat_map(
~sep=(prev, next) => comma_breakable_space,
~trail=last => ifBreaks(","),
~f=print_lambda_argument,
params,
),
),
string(" =>"),
nest_all(
(
// TODO: Is there a better way to do this?
switch (body.pexp_desc) {
| PExpBlock(_) => space
| _ => breakable_space
}
)
++ print_expression(body),
),
string(" => "),
print_expression(body),
])
| PExpContinue => string("continue")
| PExpBreak => string("break")
Expand Down
49 changes: 23 additions & 26 deletions compiler/test/grainfmt/function_params.expected.gr
Original file line number Diff line number Diff line change
Expand Up @@ -6,40 +6,37 @@ let unit_arg = () => 3

let two_args = (x, y) => 4

provide let fake_write: (int, int, int, string) => string =
(
fd,
iovs,
iovs_len,
nwritten,
) => {
provide let fake_write: (int, int, int, string) => string = (
fd,
iovs,
iovs_len,
nwritten,
) => {
"ok"
}

let lots_of_args =
(
verylonglong1,
verylonglong2,
verylonglong3,
verylonglong4,
verylonglong1,
) => {
let lots_of_args = (
verylonglong1,
verylonglong2,
verylonglong3,
verylonglong4,
verylonglong1,
) => {
print("lots of args")
}

let stringTailMatcher = (toMatch, len) =>
(
buf: Number,
pos: Number,
start: Number,
limit: Number,
end: Number,
state,
stack,
) => {
let stringTailMatcher = (toMatch, len) => (
buf: Number,
pos: Number,
start: Number,
limit: Number,
end: Number,
state,
stack,
) => {
true
}

let f: Number => (Number, Number) => Number = (a) => (b, c) => a + b + c

let foo = ((fst, snd) as pair) => pair
let foo = ((fst, snd) as pair) => pair

0 comments on commit 7e75cbc

Please sign in to comment.