Skip to content

Commit bfd522c

Browse files
committed
Printer: uncurried mode support for types
1 parent d598ad6 commit bfd522c

File tree

7 files changed

+56
-40
lines changed

7 files changed

+56
-40
lines changed

lib/4.06.1/unstable/js_compiler.ml

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54614,10 +54614,12 @@ and printLabelDeclaration ~state (ld : Parsetree.label_declaration) cmtTbl =
5461454614
and printTypExpr ~state (typExpr : Parsetree.core_type) cmtTbl =
5461554615
let printArrow ~uncurried typExpr =
5461654616
let attrsBefore, args, returnType = ParsetreeViewer.arrowType typExpr in
54617-
let uncurried, attrsBefore =
54617+
let dotted, attrsBefore =
5461854618
(* Converting .ml code to .res requires processing uncurried attributes *)
5461954619
let hasBs, attrs = ParsetreeViewer.processBsAttribute attrsBefore in
54620-
(uncurried || hasBs, attrs)
54620+
( (if state.State.uncurried_by_default then not uncurried else uncurried)
54621+
|| hasBs,
54622+
attrs )
5462154623
in
5462254624
let returnTypeNeedsParens =
5462354625
match returnType.ptyp_desc with
@@ -54631,7 +54633,7 @@ and printTypExpr ~state (typExpr : Parsetree.core_type) cmtTbl =
5463154633
in
5463254634
match args with
5463354635
| [] -> Doc.nil
54634-
| [([], Nolabel, n)] when not uncurried ->
54636+
| [([], Nolabel, n)] when not dotted ->
5463554637
let hasAttrsBefore = not (attrsBefore = []) in
5463654638
let attrs =
5463754639
if hasAttrsBefore then
@@ -54672,8 +54674,7 @@ and printTypExpr ~state (typExpr : Parsetree.core_type) cmtTbl =
5467254674
(Doc.concat
5467354675
[
5467454676
Doc.softLine;
54675-
(if uncurried then Doc.concat [Doc.dot; Doc.space]
54676-
else Doc.nil);
54677+
(if dotted then Doc.concat [Doc.dot; Doc.space] else Doc.nil);
5467754678
Doc.join
5467854679
~sep:(Doc.concat [Doc.comma; Doc.line])
5467954680
(List.map
@@ -54966,7 +54967,7 @@ and printObjectField ~state (field : Parsetree.object_field) cmtTbl =
5496654967
and printTypeParameter ~state (attrs, lbl, typ) cmtTbl =
5496754968
(* Converting .ml code to .res requires processing uncurried attributes *)
5496854969
let hasBs, attrs = ParsetreeViewer.processBsAttribute attrs in
54969-
let uncurried = if hasBs then Doc.concat [Doc.dot; Doc.space] else Doc.nil in
54970+
let dotted = if hasBs then Doc.concat [Doc.dot; Doc.space] else Doc.nil in
5497054971
let attrs = printAttributes ~state attrs cmtTbl in
5497154972
let label =
5497254973
match lbl with
@@ -54992,7 +54993,7 @@ and printTypeParameter ~state (attrs, lbl, typ) cmtTbl =
5499254993
Doc.group
5499354994
(Doc.concat
5499454995
[
54995-
uncurried;
54996+
dotted;
5499654997
attrs;
5499754998
label;
5499854999
printTypExpr ~state typ cmtTbl;

lib/4.06.1/unstable/js_playground_compiler.ml

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54614,10 +54614,12 @@ and printLabelDeclaration ~state (ld : Parsetree.label_declaration) cmtTbl =
5461454614
and printTypExpr ~state (typExpr : Parsetree.core_type) cmtTbl =
5461554615
let printArrow ~uncurried typExpr =
5461654616
let attrsBefore, args, returnType = ParsetreeViewer.arrowType typExpr in
54617-
let uncurried, attrsBefore =
54617+
let dotted, attrsBefore =
5461854618
(* Converting .ml code to .res requires processing uncurried attributes *)
5461954619
let hasBs, attrs = ParsetreeViewer.processBsAttribute attrsBefore in
54620-
(uncurried || hasBs, attrs)
54620+
( (if state.State.uncurried_by_default then not uncurried else uncurried)
54621+
|| hasBs,
54622+
attrs )
5462154623
in
5462254624
let returnTypeNeedsParens =
5462354625
match returnType.ptyp_desc with
@@ -54631,7 +54633,7 @@ and printTypExpr ~state (typExpr : Parsetree.core_type) cmtTbl =
5463154633
in
5463254634
match args with
5463354635
| [] -> Doc.nil
54634-
| [([], Nolabel, n)] when not uncurried ->
54636+
| [([], Nolabel, n)] when not dotted ->
5463554637
let hasAttrsBefore = not (attrsBefore = []) in
5463654638
let attrs =
5463754639
if hasAttrsBefore then
@@ -54672,8 +54674,7 @@ and printTypExpr ~state (typExpr : Parsetree.core_type) cmtTbl =
5467254674
(Doc.concat
5467354675
[
5467454676
Doc.softLine;
54675-
(if uncurried then Doc.concat [Doc.dot; Doc.space]
54676-
else Doc.nil);
54677+
(if dotted then Doc.concat [Doc.dot; Doc.space] else Doc.nil);
5467754678
Doc.join
5467854679
~sep:(Doc.concat [Doc.comma; Doc.line])
5467954680
(List.map
@@ -54966,7 +54967,7 @@ and printObjectField ~state (field : Parsetree.object_field) cmtTbl =
5496654967
and printTypeParameter ~state (attrs, lbl, typ) cmtTbl =
5496754968
(* Converting .ml code to .res requires processing uncurried attributes *)
5496854969
let hasBs, attrs = ParsetreeViewer.processBsAttribute attrs in
54969-
let uncurried = if hasBs then Doc.concat [Doc.dot; Doc.space] else Doc.nil in
54970+
let dotted = if hasBs then Doc.concat [Doc.dot; Doc.space] else Doc.nil in
5497054971
let attrs = printAttributes ~state attrs cmtTbl in
5497154972
let label =
5497254973
match lbl with
@@ -54992,7 +54993,7 @@ and printTypeParameter ~state (attrs, lbl, typ) cmtTbl =
5499254993
Doc.group
5499354994
(Doc.concat
5499454995
[
54995-
uncurried;
54996+
dotted;
5499654997
attrs;
5499754998
label;
5499854999
printTypExpr ~state typ cmtTbl;

lib/4.06.1/whole_compiler.ml

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -109609,10 +109609,12 @@ and printLabelDeclaration ~state (ld : Parsetree.label_declaration) cmtTbl =
109609109609
and printTypExpr ~state (typExpr : Parsetree.core_type) cmtTbl =
109610109610
let printArrow ~uncurried typExpr =
109611109611
let attrsBefore, args, returnType = ParsetreeViewer.arrowType typExpr in
109612-
let uncurried, attrsBefore =
109612+
let dotted, attrsBefore =
109613109613
(* Converting .ml code to .res requires processing uncurried attributes *)
109614109614
let hasBs, attrs = ParsetreeViewer.processBsAttribute attrsBefore in
109615-
(uncurried || hasBs, attrs)
109615+
( (if state.State.uncurried_by_default then not uncurried else uncurried)
109616+
|| hasBs,
109617+
attrs )
109616109618
in
109617109619
let returnTypeNeedsParens =
109618109620
match returnType.ptyp_desc with
@@ -109626,7 +109628,7 @@ and printTypExpr ~state (typExpr : Parsetree.core_type) cmtTbl =
109626109628
in
109627109629
match args with
109628109630
| [] -> Doc.nil
109629-
| [([], Nolabel, n)] when not uncurried ->
109631+
| [([], Nolabel, n)] when not dotted ->
109630109632
let hasAttrsBefore = not (attrsBefore = []) in
109631109633
let attrs =
109632109634
if hasAttrsBefore then
@@ -109667,8 +109669,7 @@ and printTypExpr ~state (typExpr : Parsetree.core_type) cmtTbl =
109667109669
(Doc.concat
109668109670
[
109669109671
Doc.softLine;
109670-
(if uncurried then Doc.concat [Doc.dot; Doc.space]
109671-
else Doc.nil);
109672+
(if dotted then Doc.concat [Doc.dot; Doc.space] else Doc.nil);
109672109673
Doc.join
109673109674
~sep:(Doc.concat [Doc.comma; Doc.line])
109674109675
(List.map
@@ -109961,7 +109962,7 @@ and printObjectField ~state (field : Parsetree.object_field) cmtTbl =
109961109962
and printTypeParameter ~state (attrs, lbl, typ) cmtTbl =
109962109963
(* Converting .ml code to .res requires processing uncurried attributes *)
109963109964
let hasBs, attrs = ParsetreeViewer.processBsAttribute attrs in
109964-
let uncurried = if hasBs then Doc.concat [Doc.dot; Doc.space] else Doc.nil in
109965+
let dotted = if hasBs then Doc.concat [Doc.dot; Doc.space] else Doc.nil in
109965109966
let attrs = printAttributes ~state attrs cmtTbl in
109966109967
let label =
109967109968
match lbl with
@@ -109987,7 +109988,7 @@ and printTypeParameter ~state (attrs, lbl, typ) cmtTbl =
109987109988
Doc.group
109988109989
(Doc.concat
109989109990
[
109990-
uncurried;
109991+
dotted;
109991109992
attrs;
109992109993
label;
109993109994
printTypExpr ~state typ cmtTbl;

res_syntax/src/res_printer.ml

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1550,10 +1550,12 @@ and printLabelDeclaration ~state (ld : Parsetree.label_declaration) cmtTbl =
15501550
and printTypExpr ~state (typExpr : Parsetree.core_type) cmtTbl =
15511551
let printArrow ~uncurried typExpr =
15521552
let attrsBefore, args, returnType = ParsetreeViewer.arrowType typExpr in
1553-
let uncurried, attrsBefore =
1553+
let dotted, attrsBefore =
15541554
(* Converting .ml code to .res requires processing uncurried attributes *)
15551555
let hasBs, attrs = ParsetreeViewer.processBsAttribute attrsBefore in
1556-
(uncurried || hasBs, attrs)
1556+
( (if state.State.uncurried_by_default then not uncurried else uncurried)
1557+
|| hasBs,
1558+
attrs )
15571559
in
15581560
let returnTypeNeedsParens =
15591561
match returnType.ptyp_desc with
@@ -1567,7 +1569,7 @@ and printTypExpr ~state (typExpr : Parsetree.core_type) cmtTbl =
15671569
in
15681570
match args with
15691571
| [] -> Doc.nil
1570-
| [([], Nolabel, n)] when not uncurried ->
1572+
| [([], Nolabel, n)] when not dotted ->
15711573
let hasAttrsBefore = not (attrsBefore = []) in
15721574
let attrs =
15731575
if hasAttrsBefore then
@@ -1608,8 +1610,7 @@ and printTypExpr ~state (typExpr : Parsetree.core_type) cmtTbl =
16081610
(Doc.concat
16091611
[
16101612
Doc.softLine;
1611-
(if uncurried then Doc.concat [Doc.dot; Doc.space]
1612-
else Doc.nil);
1613+
(if dotted then Doc.concat [Doc.dot; Doc.space] else Doc.nil);
16131614
Doc.join
16141615
~sep:(Doc.concat [Doc.comma; Doc.line])
16151616
(List.map
@@ -1902,7 +1903,7 @@ and printObjectField ~state (field : Parsetree.object_field) cmtTbl =
19021903
and printTypeParameter ~state (attrs, lbl, typ) cmtTbl =
19031904
(* Converting .ml code to .res requires processing uncurried attributes *)
19041905
let hasBs, attrs = ParsetreeViewer.processBsAttribute attrs in
1905-
let uncurried = if hasBs then Doc.concat [Doc.dot; Doc.space] else Doc.nil in
1906+
let dotted = if hasBs then Doc.concat [Doc.dot; Doc.space] else Doc.nil in
19061907
let attrs = printAttributes ~state attrs cmtTbl in
19071908
let label =
19081909
match lbl with
@@ -1928,7 +1929,7 @@ and printTypeParameter ~state (attrs, lbl, typ) cmtTbl =
19281929
Doc.group
19291930
(Doc.concat
19301931
[
1931-
uncurried;
1932+
dotted;
19321933
attrs;
19331934
label;
19341935
printTypExpr ~state typ cmtTbl;

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ type cTyp = string => int
1212
type uTyp = (. string) => int
1313
type mixTyp = (string, .string, string) => (string, string, string) => (string, .string) => int
1414
type bTyp = (. string) => string => int
15+
// type cTyp2 = (string, string) => int
16+
// type uTyp2 = (.string, string) => int
1517

1618
@@uncurried
1719

@@ -29,3 +31,5 @@ type cTyp = (. string) => int
2931
type uTyp = string => int
3032
type mixTyp = (.string, string, .string) => (.string, .string, .string) => (.string, string) => int
3133
type bTyp = string => (. string) => int
34+
// type cTyp2 = (.string, string) => int
35+
// type uTyp2 = (string, string) => int

res_syntax/tests/printer/expr/UncurriedByDefault.res

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@ let bracesFun = (. x) => y => x+y
88
// let cFun2 = (x, y) => 3
99
// let uFun2 = (. x, y) => 3
1010

11-
// type cTyp = string => int
12-
// type uTyp = (. string) => int
13-
// type mixTyp = (string, .string, string) => (string, string, string) => (string, .string) => int
14-
// type bTyp = (. string) => string => int
11+
type cTyp = string => int
12+
type uTyp = (. string) => int
13+
type mixTyp = (string, .string, string) => (string, string, string) => (string, .string) => int
14+
type bTyp = (. string) => string => int
15+
// type cTyp2 = (string, string) => int
16+
// type uTyp2 = (.string, string) => int
1517

1618
@@uncurried
1719

@@ -25,7 +27,9 @@ let bracesFun = x => (. y) => x+y
2527
// let cFun2 = (. x, y) => 3
2628
// let uFun2 = (x, y) => 3
2729

28-
// type cTyp = (. string) => int
29-
// type uTyp = string => int
30+
type cTyp = (. string) => int
31+
type uTyp = string => int
3032
// type mixTyp = (.string, string, .string) => (.string, .string, .string) => (.string, string) => int
3133
// type bTyp = string => (. string) => int
34+
// type cTyp2 = (. string, string) => int
35+
// type uTyp2 = (string, string) => int

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

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@ let bracesFun = (. x) => {y => x + y}
88
// let cFun2 = (x, y) => 3
99
// let uFun2 = (. x, y) => 3
1010

11-
// type cTyp = string => int
12-
// type uTyp = (. string) => int
13-
// type mixTyp = (string, .string, string) => (string, string, string) => (string, .string) => int
14-
// type bTyp = (. string) => string => int
11+
type cTyp = string => int
12+
type uTyp = (. string) => int
13+
type mixTyp = string => (. string, string, string, string, string, string) => (. string) => int
14+
type bTyp = (. string, string) => int
15+
// type cTyp2 = (string, string) => int
16+
// type uTyp2 = (.string, string) => int
1517

1618
@@uncurried
1719

@@ -25,7 +27,9 @@ let bracesFun = x => {(. y) => x + y}
2527
// let cFun2 = (. x, y) => 3
2628
// let uFun2 = (x, y) => 3
2729

28-
// type cTyp = (. string) => int
29-
// type uTyp = string => int
30+
type cTyp = (. string) => int
31+
type uTyp = string => int
3032
// type mixTyp = (.string, string, .string) => (.string, .string, .string) => (.string, string) => int
3133
// type bTyp = string => (. string) => int
34+
// type cTyp2 = (. string, string) => int
35+
// type uTyp2 = (string, string) => int

0 commit comments

Comments
 (0)