Skip to content

Commit d598ad6

Browse files
committed
Printer: uncurried mode support for function declarations
1 parent f931af4 commit d598ad6

File tree

7 files changed

+62
-62
lines changed

7 files changed

+62
-62
lines changed

lib/4.06.1/unstable/js_compiler.ml

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -57776,6 +57776,9 @@ and printCase ~state (case : Parsetree.case) cmtTbl =
5777657776

5777757777
and printExprFunParameters ~state ~inCallback ~async ~uncurried ~hasConstraint
5777857778
parameters cmtTbl =
57779+
let dotted =
57780+
if state.State.uncurried_by_default then not uncurried else uncurried
57781+
in
5777957782
match parameters with
5778057783
(* let f = _ => () *)
5778157784
| [
@@ -57787,7 +57790,7 @@ and printExprFunParameters ~state ~inCallback ~async ~uncurried ~hasConstraint
5778757790
pat = {Parsetree.ppat_desc = Ppat_any; ppat_loc};
5778857791
};
5778957792
]
57790-
when not uncurried ->
57793+
when not dotted ->
5779157794
let any =
5779257795
let doc = if hasConstraint then Doc.text "(_)" else Doc.text "_" in
5779357796
printComments doc cmtTbl ppat_loc
@@ -57807,7 +57810,7 @@ and printExprFunParameters ~state ~inCallback ~async ~uncurried ~hasConstraint
5780757810
};
5780857811
};
5780957812
]
57810-
when not uncurried ->
57813+
when not dotted ->
5781157814
let txtDoc =
5781257815
let var = printIdentLike stringLoc.txt in
5781357816
let var =
@@ -57831,7 +57834,7 @@ and printExprFunParameters ~state ~inCallback ~async ~uncurried ~hasConstraint
5783157834
{ppat_desc = Ppat_construct ({txt = Longident.Lident "()"; loc}, None)};
5783257835
};
5783357836
]
57834-
when not uncurried ->
57837+
when not dotted ->
5783557838
let doc =
5783657839
let lparenRparen = Doc.text "()" in
5783757840
if async then addAsync lparenRparen else lparenRparen
@@ -57845,7 +57848,7 @@ and printExprFunParameters ~state ~inCallback ~async ~uncurried ~hasConstraint
5784557848
| _ -> false
5784657849
in
5784757850
let maybeAsyncLparen =
57848-
let lparen = if uncurried then Doc.text "(. " else Doc.lparen in
57851+
let lparen = if dotted then Doc.text "(. " else Doc.lparen in
5784957852
if async then addAsync lparen else lparen
5785057853
in
5785157854
let shouldHug = ParsetreeViewer.parametersShouldHug parameters in
@@ -57889,9 +57892,7 @@ and printExpFunParameter ~state parameter cmtTbl =
5788957892
])
5789057893
| Parameter {attrs; lbl; defaultExpr; pat = pattern} ->
5789157894
let hasBs, attrs = ParsetreeViewer.processBsAttribute attrs in
57892-
let uncurried =
57893-
if hasBs then Doc.concat [Doc.dot; Doc.space] else Doc.nil
57894-
in
57895+
let dotted = if hasBs then Doc.concat [Doc.dot; Doc.space] else Doc.nil in
5789557896
let attrs = printAttributes ~state attrs cmtTbl in
5789657897
(* =defaultValue *)
5789757898
let defaultExprDoc =
@@ -57950,11 +57951,7 @@ and printExpFunParameter ~state parameter cmtTbl =
5795057951
Doc.group
5795157952
(Doc.concat
5795257953
[
57953-
uncurried;
57954-
attrs;
57955-
labelWithPattern;
57956-
defaultExprDoc;
57957-
optionalLabelSuffix;
57954+
dotted; attrs; labelWithPattern; defaultExprDoc; optionalLabelSuffix;
5795857955
])
5795957956
in
5796057957
let cmtLoc =

lib/4.06.1/unstable/js_playground_compiler.ml

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -57776,6 +57776,9 @@ and printCase ~state (case : Parsetree.case) cmtTbl =
5777657776

5777757777
and printExprFunParameters ~state ~inCallback ~async ~uncurried ~hasConstraint
5777857778
parameters cmtTbl =
57779+
let dotted =
57780+
if state.State.uncurried_by_default then not uncurried else uncurried
57781+
in
5777957782
match parameters with
5778057783
(* let f = _ => () *)
5778157784
| [
@@ -57787,7 +57790,7 @@ and printExprFunParameters ~state ~inCallback ~async ~uncurried ~hasConstraint
5778757790
pat = {Parsetree.ppat_desc = Ppat_any; ppat_loc};
5778857791
};
5778957792
]
57790-
when not uncurried ->
57793+
when not dotted ->
5779157794
let any =
5779257795
let doc = if hasConstraint then Doc.text "(_)" else Doc.text "_" in
5779357796
printComments doc cmtTbl ppat_loc
@@ -57807,7 +57810,7 @@ and printExprFunParameters ~state ~inCallback ~async ~uncurried ~hasConstraint
5780757810
};
5780857811
};
5780957812
]
57810-
when not uncurried ->
57813+
when not dotted ->
5781157814
let txtDoc =
5781257815
let var = printIdentLike stringLoc.txt in
5781357816
let var =
@@ -57831,7 +57834,7 @@ and printExprFunParameters ~state ~inCallback ~async ~uncurried ~hasConstraint
5783157834
{ppat_desc = Ppat_construct ({txt = Longident.Lident "()"; loc}, None)};
5783257835
};
5783357836
]
57834-
when not uncurried ->
57837+
when not dotted ->
5783557838
let doc =
5783657839
let lparenRparen = Doc.text "()" in
5783757840
if async then addAsync lparenRparen else lparenRparen
@@ -57845,7 +57848,7 @@ and printExprFunParameters ~state ~inCallback ~async ~uncurried ~hasConstraint
5784557848
| _ -> false
5784657849
in
5784757850
let maybeAsyncLparen =
57848-
let lparen = if uncurried then Doc.text "(. " else Doc.lparen in
57851+
let lparen = if dotted then Doc.text "(. " else Doc.lparen in
5784957852
if async then addAsync lparen else lparen
5785057853
in
5785157854
let shouldHug = ParsetreeViewer.parametersShouldHug parameters in
@@ -57889,9 +57892,7 @@ and printExpFunParameter ~state parameter cmtTbl =
5788957892
])
5789057893
| Parameter {attrs; lbl; defaultExpr; pat = pattern} ->
5789157894
let hasBs, attrs = ParsetreeViewer.processBsAttribute attrs in
57892-
let uncurried =
57893-
if hasBs then Doc.concat [Doc.dot; Doc.space] else Doc.nil
57894-
in
57895+
let dotted = if hasBs then Doc.concat [Doc.dot; Doc.space] else Doc.nil in
5789557896
let attrs = printAttributes ~state attrs cmtTbl in
5789657897
(* =defaultValue *)
5789757898
let defaultExprDoc =
@@ -57950,11 +57951,7 @@ and printExpFunParameter ~state parameter cmtTbl =
5795057951
Doc.group
5795157952
(Doc.concat
5795257953
[
57953-
uncurried;
57954-
attrs;
57955-
labelWithPattern;
57956-
defaultExprDoc;
57957-
optionalLabelSuffix;
57954+
dotted; attrs; labelWithPattern; defaultExprDoc; optionalLabelSuffix;
5795857955
])
5795957956
in
5796057957
let cmtLoc =

lib/4.06.1/whole_compiler.ml

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -112771,6 +112771,9 @@ and printCase ~state (case : Parsetree.case) cmtTbl =
112771112771

112772112772
and printExprFunParameters ~state ~inCallback ~async ~uncurried ~hasConstraint
112773112773
parameters cmtTbl =
112774+
let dotted =
112775+
if state.State.uncurried_by_default then not uncurried else uncurried
112776+
in
112774112777
match parameters with
112775112778
(* let f = _ => () *)
112776112779
| [
@@ -112782,7 +112785,7 @@ and printExprFunParameters ~state ~inCallback ~async ~uncurried ~hasConstraint
112782112785
pat = {Parsetree.ppat_desc = Ppat_any; ppat_loc};
112783112786
};
112784112787
]
112785-
when not uncurried ->
112788+
when not dotted ->
112786112789
let any =
112787112790
let doc = if hasConstraint then Doc.text "(_)" else Doc.text "_" in
112788112791
printComments doc cmtTbl ppat_loc
@@ -112802,7 +112805,7 @@ and printExprFunParameters ~state ~inCallback ~async ~uncurried ~hasConstraint
112802112805
};
112803112806
};
112804112807
]
112805-
when not uncurried ->
112808+
when not dotted ->
112806112809
let txtDoc =
112807112810
let var = printIdentLike stringLoc.txt in
112808112811
let var =
@@ -112826,7 +112829,7 @@ and printExprFunParameters ~state ~inCallback ~async ~uncurried ~hasConstraint
112826112829
{ppat_desc = Ppat_construct ({txt = Longident.Lident "()"; loc}, None)};
112827112830
};
112828112831
]
112829-
when not uncurried ->
112832+
when not dotted ->
112830112833
let doc =
112831112834
let lparenRparen = Doc.text "()" in
112832112835
if async then addAsync lparenRparen else lparenRparen
@@ -112840,7 +112843,7 @@ and printExprFunParameters ~state ~inCallback ~async ~uncurried ~hasConstraint
112840112843
| _ -> false
112841112844
in
112842112845
let maybeAsyncLparen =
112843-
let lparen = if uncurried then Doc.text "(. " else Doc.lparen in
112846+
let lparen = if dotted then Doc.text "(. " else Doc.lparen in
112844112847
if async then addAsync lparen else lparen
112845112848
in
112846112849
let shouldHug = ParsetreeViewer.parametersShouldHug parameters in
@@ -112884,9 +112887,7 @@ and printExpFunParameter ~state parameter cmtTbl =
112884112887
])
112885112888
| Parameter {attrs; lbl; defaultExpr; pat = pattern} ->
112886112889
let hasBs, attrs = ParsetreeViewer.processBsAttribute attrs in
112887-
let uncurried =
112888-
if hasBs then Doc.concat [Doc.dot; Doc.space] else Doc.nil
112889-
in
112890+
let dotted = if hasBs then Doc.concat [Doc.dot; Doc.space] else Doc.nil in
112890112891
let attrs = printAttributes ~state attrs cmtTbl in
112891112892
(* =defaultValue *)
112892112893
let defaultExprDoc =
@@ -112945,11 +112946,7 @@ and printExpFunParameter ~state parameter cmtTbl =
112945112946
Doc.group
112946112947
(Doc.concat
112947112948
[
112948-
uncurried;
112949-
attrs;
112950-
labelWithPattern;
112951-
defaultExprDoc;
112952-
optionalLabelSuffix;
112949+
dotted; attrs; labelWithPattern; defaultExprDoc; optionalLabelSuffix;
112953112950
])
112954112951
in
112955112952
let cmtLoc =

res_syntax/src/res_printer.ml

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4712,6 +4712,9 @@ and printCase ~state (case : Parsetree.case) cmtTbl =
47124712

47134713
and printExprFunParameters ~state ~inCallback ~async ~uncurried ~hasConstraint
47144714
parameters cmtTbl =
4715+
let dotted =
4716+
if state.State.uncurried_by_default then not uncurried else uncurried
4717+
in
47154718
match parameters with
47164719
(* let f = _ => () *)
47174720
| [
@@ -4723,7 +4726,7 @@ and printExprFunParameters ~state ~inCallback ~async ~uncurried ~hasConstraint
47234726
pat = {Parsetree.ppat_desc = Ppat_any; ppat_loc};
47244727
};
47254728
]
4726-
when not uncurried ->
4729+
when not dotted ->
47274730
let any =
47284731
let doc = if hasConstraint then Doc.text "(_)" else Doc.text "_" in
47294732
printComments doc cmtTbl ppat_loc
@@ -4743,7 +4746,7 @@ and printExprFunParameters ~state ~inCallback ~async ~uncurried ~hasConstraint
47434746
};
47444747
};
47454748
]
4746-
when not uncurried ->
4749+
when not dotted ->
47474750
let txtDoc =
47484751
let var = printIdentLike stringLoc.txt in
47494752
let var =
@@ -4767,7 +4770,7 @@ and printExprFunParameters ~state ~inCallback ~async ~uncurried ~hasConstraint
47674770
{ppat_desc = Ppat_construct ({txt = Longident.Lident "()"; loc}, None)};
47684771
};
47694772
]
4770-
when not uncurried ->
4773+
when not dotted ->
47714774
let doc =
47724775
let lparenRparen = Doc.text "()" in
47734776
if async then addAsync lparenRparen else lparenRparen
@@ -4781,7 +4784,7 @@ and printExprFunParameters ~state ~inCallback ~async ~uncurried ~hasConstraint
47814784
| _ -> false
47824785
in
47834786
let maybeAsyncLparen =
4784-
let lparen = if uncurried then Doc.text "(. " else Doc.lparen in
4787+
let lparen = if dotted then Doc.text "(. " else Doc.lparen in
47854788
if async then addAsync lparen else lparen
47864789
in
47874790
let shouldHug = ParsetreeViewer.parametersShouldHug parameters in
@@ -4825,9 +4828,7 @@ and printExpFunParameter ~state parameter cmtTbl =
48254828
])
48264829
| Parameter {attrs; lbl; defaultExpr; pat = pattern} ->
48274830
let hasBs, attrs = ParsetreeViewer.processBsAttribute attrs in
4828-
let uncurried =
4829-
if hasBs then Doc.concat [Doc.dot; Doc.space] else Doc.nil
4830-
in
4831+
let dotted = if hasBs then Doc.concat [Doc.dot; Doc.space] else Doc.nil in
48314832
let attrs = printAttributes ~state attrs cmtTbl in
48324833
(* =defaultValue *)
48334834
let defaultExprDoc =
@@ -4886,11 +4887,7 @@ and printExpFunParameter ~state parameter cmtTbl =
48864887
Doc.group
48874888
(Doc.concat
48884889
[
4889-
uncurried;
4890-
attrs;
4891-
labelWithPattern;
4892-
defaultExprDoc;
4893-
optionalLabelSuffix;
4890+
dotted; attrs; labelWithPattern; defaultExprDoc; optionalLabelSuffix;
48944891
])
48954892
in
48964893
let cmtLoc =

res_syntax/tests/parsing/grammar/expressions/UncurriedByDefault.res

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ let cFun = x => 3
55
let uFun = (.x) => 3
66
let mixFun = (a, .b, c) => (d, e, f) => (g, .h) => 4
77
let bracesFun = (. x) => y => x+y
8+
// let cFun2 = (x, y) => 3
9+
// let uFun2 = (. x, y) => 3
810

911
type cTyp = string => int
1012
type uTyp = (. string) => int
@@ -20,6 +22,8 @@ let cFun = (. x) => 3
2022
let uFun = x => 3
2123
let mixFun = (.a, b, .c) => (.d, .e, .f) => (.g, h) => 4
2224
let bracesFun = x => (. y) => x+y
25+
// let cFun2 = (. x, y) => 3
26+
// let uFun2 = (x, y) => 3
2327

2428
type cTyp = (. string) => int
2529
type uTyp = string => int

res_syntax/tests/printer/expr/UncurriedByDefault.res

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
let cApp = foo(3)
22
let uApp = foo(. 3)
33

4-
// let cFun = x => 3
5-
// let uFun = (.x) => 3
6-
// let mixFun = (a, .b, c) => (d, e, f) => (g, .h) => 4
7-
// let bracesFun = (. x) => y => x+y
4+
let cFun = x => 3
5+
let uFun = (.x) => 3
6+
//let mixFun = (a, .b, c) => (d, e, f) => (g, .h) => 4
7+
let bracesFun = (. x) => y => x+y
8+
// let cFun2 = (x, y) => 3
9+
// let uFun2 = (. x, y) => 3
810

911
// type cTyp = string => int
1012
// type uTyp = (. string) => int
@@ -16,10 +18,12 @@ let uApp = foo(. 3)
1618
let cApp = foo(. 3)
1719
let uApp = foo(3)
1820

19-
// let cFun = (. x) => 3
20-
// let uFun = x => 3
21+
let cFun = (. x) => 3
22+
let uFun = x => 3
2123
// let mixFun = (.a, b, .c) => (.d, .e, .f) => (.g, h) => 4
22-
// let bracesFun = x => (. y) => x+y
24+
let bracesFun = x => (. y) => x+y
25+
// let cFun2 = (. x, y) => 3
26+
// let uFun2 = (x, y) => 3
2327

2428
// type cTyp = (. string) => int
2529
// type uTyp = string => int

res_syntax/tests/printer/expr/expected/UncurriedByDefault.res.txt

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
let cApp = foo(3)
22
let uApp = foo(. 3)
33

4-
// let cFun = x => 3
5-
// let uFun = (.x) => 3
6-
// let mixFun = (a, .b, c) => (d, e, f) => (g, .h) => 4
7-
// let bracesFun = (. x) => y => x+y
4+
let cFun = x => 3
5+
let uFun = (. x) => 3
6+
//let mixFun = (a, .b, c) => (d, e, f) => (g, .h) => 4
7+
let bracesFun = (. x) => {y => x + y}
8+
// let cFun2 = (x, y) => 3
9+
// let uFun2 = (. x, y) => 3
810

911
// type cTyp = string => int
1012
// type uTyp = (. string) => int
@@ -16,10 +18,12 @@ let uApp = foo(. 3)
1618
let cApp = foo(. 3)
1719
let uApp = foo(3)
1820

19-
// let cFun = (. x) => 3
20-
// let uFun = x => 3
21+
let cFun = (. x) => 3
22+
let uFun = x => 3
2123
// let mixFun = (.a, b, .c) => (.d, .e, .f) => (.g, h) => 4
22-
// let bracesFun = x => (. y) => x+y
24+
let bracesFun = x => {(. y) => x + y}
25+
// let cFun2 = (. x, y) => 3
26+
// let uFun2 = (x, y) => 3
2327

2428
// type cTyp = (. string) => int
2529
// type uTyp = string => int

0 commit comments

Comments
 (0)