Skip to content

Commit 16dffdf

Browse files
committed
printer
1 parent 97ec4d6 commit 16dffdf

File tree

77 files changed

+1193
-1613
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+1193
-1613
lines changed

compiler/ml/pprintast.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -954,7 +954,7 @@ and binding ctxt f {pvb_pat=p; pvb_expr=x; _} =
954954
| Pexp_fun (label, eo, p, e, arity) ->
955955
let arity_str = match arity with
956956
| None -> ""
957-
| Some arity -> "arity:" ^ string_of_int arity
957+
| Some arity -> "[arity:" ^ string_of_int arity ^ "]"
958958
in
959959
if label=Nolabel then
960960
pp f "%s%a@ %a" arity_str (simple_pattern ctxt) p pp_print_pexp_function e

compiler/syntax/src/res_parens.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ let ternary_operand expr =
304304
Nothing
305305
| {pexp_desc = Pexp_constraint _} -> Parenthesized
306306
| _ when Res_parsetree_viewer.is_fun_newtype expr -> (
307-
let _uncurried, _attrsOnArrow, _parameters, return_expr =
307+
let _attrsOnArrow, _parameters, return_expr =
308308
ParsetreeViewer.fun_expr expr
309309
in
310310
match return_expr.pexp_desc with

compiler/syntax/src/res_parsetree_viewer.ml

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ let fun_expr expr =
178178
collect_new_types (string_loc :: acc) return_expr
179179
| return_expr -> (List.rev acc, return_expr)
180180
in
181-
let rec collect ~uncurried ~n_fun attrs_before acc expr =
181+
let rec collect ~n_fun attrs_before acc expr =
182182
match expr with
183183
| {
184184
pexp_desc =
@@ -189,37 +189,32 @@ let fun_expr expr =
189189
{pexp_desc = Pexp_apply _},
190190
_ );
191191
} ->
192-
(uncurried, attrs_before, List.rev acc, rewrite_underscore_apply expr)
192+
(attrs_before, List.rev acc, rewrite_underscore_apply expr)
193193
| {pexp_desc = Pexp_newtype (string_loc, rest); pexp_attributes = attrs} ->
194194
let string_locs, return_expr = collect_new_types [string_loc] rest in
195195
let param = NewTypes {attrs; locs = string_locs} in
196-
collect ~uncurried ~n_fun attrs_before (param :: acc) return_expr
196+
collect ~n_fun attrs_before (param :: acc) return_expr
197197
| {
198-
pexp_desc = Pexp_fun (lbl, default_expr, pattern, return_expr, _);
198+
pexp_desc = Pexp_fun (lbl, default_expr, pattern, return_expr, arity);
199199
pexp_attributes = [];
200-
} ->
200+
}
201+
when arity = None || n_fun = 0 ->
201202
let parameter =
202203
Parameter {attrs = []; lbl; default_expr; pat = pattern}
203204
in
204-
collect ~uncurried ~n_fun:(n_fun + 1) attrs_before (parameter :: acc)
205-
return_expr
205+
collect ~n_fun:(n_fun + 1) attrs_before (parameter :: acc) return_expr
206206
(* If a fun has an attribute, then it stops here and makes currying.
207207
i.e attributes outside of (...), uncurried `(.)` and `async` make currying *)
208-
| {pexp_desc = Pexp_fun _} -> (uncurried, attrs_before, List.rev acc, expr)
208+
| {pexp_desc = Pexp_fun _} -> (attrs_before, List.rev acc, expr)
209209
| expr when n_fun = 0 && Ast_uncurried.expr_is_uncurried_fun expr ->
210210
let expr = Ast_uncurried.expr_extract_uncurried_fun expr in
211-
collect ~uncurried:true ~n_fun attrs_before acc expr
212-
| expr -> (uncurried, attrs_before, List.rev acc, expr)
211+
collect ~n_fun attrs_before acc expr
212+
| expr -> (attrs_before, List.rev acc, expr)
213213
in
214214
match expr with
215215
| {pexp_desc = Pexp_fun _ | Pexp_newtype _} ->
216-
collect ~uncurried:false ~n_fun:0 expr.pexp_attributes []
217-
{expr with pexp_attributes = []}
218-
| _ when Ast_uncurried.expr_is_uncurried_fun expr ->
219-
let expr = Ast_uncurried.expr_extract_uncurried_fun expr in
220-
collect ~uncurried:true ~n_fun:0 expr.pexp_attributes []
221-
{expr with pexp_attributes = []}
222-
| _ -> collect ~uncurried:false ~n_fun:0 [] [] expr
216+
collect ~n_fun:0 expr.pexp_attributes [] {expr with pexp_attributes = []}
217+
| _ -> collect ~n_fun:0 [] [] expr
223218

224219
let process_braces_attr expr =
225220
match expr.pexp_attributes with

compiler/syntax/src/res_parsetree_viewer.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ type fun_param_kind =
6161

6262
val fun_expr :
6363
Parsetree.expression ->
64-
bool * Parsetree.attributes * fun_param_kind list * Parsetree.expression
64+
Parsetree.attributes * fun_param_kind list * Parsetree.expression
6565

6666
(* example:
6767
* `makeCoordinate({

compiler/syntax/src/res_printer.ml

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1988,9 +1988,7 @@ and print_value_binding ~state ~rec_flag (vb : Parsetree.value_binding) cmt_tbl
19881988
};
19891989
pvb_expr = {pexp_desc = Pexp_newtype _} as expr;
19901990
} -> (
1991-
let _uncurried, _attrs, parameters, return_expr =
1992-
ParsetreeViewer.fun_expr expr
1993-
in
1991+
let _attrs, parameters, return_expr = ParsetreeViewer.fun_expr expr in
19941992
let abstract_type =
19951993
match parameters with
19961994
| [NewTypes {locs = vars}] ->
@@ -2703,9 +2701,7 @@ and print_if_chain ~state pexp_attributes ifs else_expr cmt_tbl =
27032701

27042702
and print_expression ~state (e : Parsetree.expression) cmt_tbl =
27052703
let print_arrow e =
2706-
let _, attrs_on_arrow, parameters, return_expr =
2707-
ParsetreeViewer.fun_expr e
2708-
in
2704+
let attrs_on_arrow, parameters, return_expr = ParsetreeViewer.fun_expr e in
27092705
let ParsetreeViewer.{async; attributes = attrs} =
27102706
ParsetreeViewer.process_function_attributes attrs_on_arrow
27112707
in
@@ -3447,7 +3443,7 @@ and print_expression ~state (e : Parsetree.expression) cmt_tbl =
34473443
| _ -> expr_with_await
34483444

34493445
and print_pexp_fun ~state ~in_callback e cmt_tbl =
3450-
let _, attrs_on_arrow, parameters, return_expr = ParsetreeViewer.fun_expr e in
3446+
let attrs_on_arrow, parameters, return_expr = ParsetreeViewer.fun_expr e in
34513447
let ParsetreeViewer.{async; attributes = attrs} =
34523448
ParsetreeViewer.process_function_attributes attrs_on_arrow
34533449
in

tests/syntax_tests/data/conversion/reason/expected/fastPipe.res.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Element.querySelectorAll(selector, element)
77

88
let x = @attr ((@attr2 a)->f(b)->c(d))
99

10-
5->(doStuff(3, _, 7))
10+
5->doStuff(3, _, 7)
1111

1212
(event->target)["value"]
1313

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
let photo = (Array.get(_, 0))(filterNone(pricedRoom["room"]["photos"]))
1+
let photo = Array.get(_, 0)(filterNone(pricedRoom["room"]["photos"]))

tests/syntax_tests/data/parsing/errors/expressions/expected/array.res.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@
88

99
Did you forget a `]` here?
1010

11-
let xs = x.map (Function$ (fun [arity:1]key -> [|key;(predicates.(key))|]))
11+
let xs = x.map (fun [arity:1]key -> [|key;(predicates.(key))|])

tests/syntax_tests/data/parsing/errors/expressions/expected/arrow.res.txt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,5 @@
99
Did you forget a `,` here?
1010

1111
;;(Object.keys providers).reduce
12-
(Function$
13-
(fun [arity:2]elements ->
14-
fun providerId -> ((let x = 1 in let b = 2 in x + b)[@res.braces ])))
12+
(fun [arity:2]elements ->
13+
fun providerId -> ((let x = 1 in let b = 2 in x + b)[@res.braces ]))

tests/syntax_tests/data/parsing/errors/expressions/expected/block.res.txt

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -63,26 +63,21 @@
6363

6464
Looks like there might be an expression missing here
6565

66-
let findThreadByIdLinearScan =
67-
Function$
68-
(fun [arity:2]~threads:((threads)[@res.namedArgLoc ]) ->
69-
fun ~id:((id)[@res.namedArgLoc ]) ->
70-
((Js.Array2.findi ThreadsModel.threads
71-
(Function$
72-
(fun [arity:2]thread ->
73-
fun i ->
74-
((let thisId =
75-
match thread with
76-
| ServerData.OneToOne
77-
{ otherPersonIDWhichIsAlsoThreadID } ->
78-
otherPersonIDWhichIsAlsoThreadID
79-
| Group { id } -> id
80-
| Unknown { id } ->
81-
(unknown.id |.u Js.String.make) |.u
82-
FBID.ofStringUnsafe in
83-
thisId == id)
84-
[@res.braces ]))))
85-
[@res.braces ]))
66+
let findThreadByIdLinearScan [arity:2]~threads:((threads)[@res.namedArgLoc ])
67+
~id:((id)[@res.namedArgLoc ]) =
68+
((Js.Array2.findi ThreadsModel.threads
69+
(fun [arity:2]thread ->
70+
fun i ->
71+
((let thisId =
72+
match thread with
73+
| ServerData.OneToOne { otherPersonIDWhichIsAlsoThreadID } ->
74+
otherPersonIDWhichIsAlsoThreadID
75+
| Group { id } -> id
76+
| Unknown { id } ->
77+
(unknown.id |.u Js.String.make) |.u FBID.ofStringUnsafe in
78+
thisId == id)
79+
[@res.braces ])))
80+
[@res.braces ])
8681
let x = ((loop 0 (Nil |.u (push doc)))[@res.braces ])
8782
;;match stack with
8883
| Empty -> [%rescript.exprhole ]

0 commit comments

Comments
 (0)