diff --git a/formatTest/typeCheckedTests/expected_output/reasonComments.re b/formatTest/typeCheckedTests/expected_output/reasonComments.re
index 63b87d939..cc85539e9 100644
--- a/formatTest/typeCheckedTests/expected_output/reasonComments.re
+++ b/formatTest/typeCheckedTests/expected_output/reasonComments.re
@@ -148,46 +148,41 @@ type t2 = (int, int); /* End of line on (int, int) */
type t3 = (int, int); /* End of line on (int, int) */
-type variant =
- | X(int, int) /* End of line on X */
- | Y(int, int); /* End of line on Y */ /* Comment on entire type def for variant */
+type variant = | X(int, int) /* End of line on X */
+ | Y(int, int); /* End of line on Y */ /* Comment on entire type def for variant */
/* Before let */
-let res =
- /* Before switch */
- switch (X(2, 3)) {
- /* Above X line */
- | X(_) => "result of X" /* End of arrow and X line */
- /* Above Y line */
- | Y(_) => "result of Y" /* End of arrow and Y line */
- }; /* After final semi in switch */
-
-let res =
- switch (X(2, 3)) {
- | X(0, 0) =>
- /* After X arrow */
- "result of X" /* End of X body line */
- | X(1, 0) /* Before X's arrow */ => "result of X" /* End of X body line */
- | X(_) =>
- /* After X _ arrow */
- "result of X" /* End of X body line */
- /* Above Y line */
- | Y(_) =>
- /* Comment above Y body */
- "result of Y"
- };
-
-type variant2 =
- /* Comment above X */
- | X(int, int) /* End of line on X */
- /* Comment above Y */
- | Y(int, int);
-
-type variant3 =
- /* Comment above X */
- | X(int, int) /* End of line on X */
- /* Comment above Y */
- | Y(int, int); /* End of line on Y */
+let res = /* Before switch */
+ switch (X(2, 3)) {
+ /* Above X line */
+ | X(_) => "result of X" /* End of arrow and X line */
+ /* Above Y line */
+ | Y(_) => "result of Y" /* End of arrow and Y line */
+ }; /* After final semi in switch */
+
+let res = switch (X(2, 3)) {
+| X(0, 0) =>
+ /* After X arrow */
+ "result of X" /* End of X body line */
+| X(1, 0) /* Before X's arrow */ => "result of X" /* End of X body line */
+| X(_) =>
+ /* After X _ arrow */
+ "result of X" /* End of X body line */
+/* Above Y line */
+| Y(_) =>
+ /* Comment above Y body */
+ "result of Y"
+};
+
+type variant2 = /* Comment above X */
+ | X(int, int) /* End of line on X */
+ /* Comment above Y */
+ | Y(int, int);
+
+type variant3 = /* Comment above X */
+ | X(int, int) /* End of line on X */
+ /* Comment above Y */
+ | Y(int, int); /* End of line on Y */
type x = {
/* not attached *above* x */
@@ -209,47 +204,44 @@ and y2 = {
fieldTwo: int,
};
-let result =
- switch (None) {
- | Some({fieldOne: 20, fieldA: a}) =>
- /* Where does this comment go? */
- let tmp = 0;
- 2 + tmp;
- | Some({fieldOne: n, fieldA: a}) =>
- /* How about this one */
- let tmp = n;
- n + tmp;
- | None => 20
- };
-
-let res =
- /* Before switch */
- switch (X(2, 3)) {
- /* Above X line */
- | X(_) => "result of X" /* End of arrow and X line */
- /* Above Y line */
- | Y(_) => "result of Y" /* End of arrow and Y line */
- };
+let result = switch (None) {
+| Some({fieldOne: 20, fieldA: a}) =>
+ /* Where does this comment go? */
+ let tmp = 0;
+ 2 + tmp;
+| Some({fieldOne: n, fieldA: a}) =>
+ /* How about this one */
+ let tmp = n;
+ n + tmp;
+| None => 20
+};
+
+let res = /* Before switch */
+ switch (X(2, 3)) {
+ /* Above X line */
+ | X(_) => "result of X" /* End of arrow and X line */
+ /* Above Y line */
+ | Y(_) => "result of Y" /* End of arrow and Y line */
+ };
/*
* Now these end of line comments *should* be retained.
*/
-let result =
- switch (None) {
- | Some({
- fieldOne: 20, /* end of line */
- fieldA: a /* end of line */
- }) =>
- let tmp = 0;
- 2 + tmp;
- | Some({
- fieldOne: n, /* end of line */
- fieldA: a /* end of line */
- }) =>
- let tmp = n;
- n + tmp;
- | None => 20
- };
+let result = switch (None) {
+| Some({
+ fieldOne: 20, /* end of line */
+ fieldA: a /* end of line */
+ }) =>
+ let tmp = 0;
+ 2 + tmp;
+| Some({
+ fieldOne: n, /* end of line */
+ fieldA: a /* end of line */
+ }) =>
+ let tmp = n;
+ n + tmp;
+| None => 20
+};
/*
* These end of line comments *should* be retained.
@@ -257,38 +249,35 @@ let result =
* implement label breaking eol behavior much like we did with sequences.
* Otherwise, right now they are not idempotent.
*/
-let res =
- switch (
- /* Retain this */
- X(2, 3)
- ) {
- /* Above X line */
- | X(
- _, /* retain this */
- _ /* retain this */
- ) => "result of X"
-
- /* Above Y line */
- | Y(_) => "result of Y" /* End of arrow and Y line */
- };
-
-type optionalTuple =
- | OptTup(
- option(
- (
- int, /* First int */
- int /* Second int */
- ),
- ),
- );
-
-type optionTuple =
- option(
- (
- int, /* First int */
- int /* Second int */
- ),
- );
+let res = switch (
+ /* Retain this */
+ X(2, 3)
+) {
+/* Above X line */
+| X(
+ _, /* retain this */
+ _ /* retain this */
+ ) => "result of X"
+
+/* Above Y line */
+| Y(_) => "result of Y" /* End of arrow and Y line */
+};
+
+type optionalTuple = | OptTup(
+ option(
+ (
+ int, /* First int */
+ int /* Second int */
+ ),
+ ),
+ );
+
+type optionTuple = option(
+ (
+ int, /* First int */
+ int /* Second int */
+ ),
+);
type intPair = (
int, /* First int */
@@ -301,11 +290,10 @@ type intPair2 = (
int,
);
-let result =
- /**/
- {
- 2 + 3;
- };
+let result = /**/
+ {
+ 2 + 3;
+ };
/* This is not yet idempotent */
/* { */
@@ -324,35 +312,38 @@ if (true) {
()
};
-type color =
- | Red(int) /* After red end of line */
- | Black(int) /* After black end of line */
- | Green(int); /* After green end of line */ /* On next line after color type def */
+type color = | Red(int) /* After red end of line */
+ | Black(int) /* After black end of line */
+ | Green(int); /* After green end of line */ /* On next line after color type def */
-let blahCurriedX = x =>
- fun
- | Red(10)
- | Black(20)
- | Green(10) => 1 /* After or pattern green */
- | Red(x) => 0 /* After red */
- | Black(x) => 0 /* After black */
- | Green(x) => 0; /* After second green */ /* On next line after blahCurriedX def */
+let blahCurriedX = x => fun
+ | Red(10)
+ | Black(20)
+ | Green(10) => 1 /* After or pattern green */
+ | Red(x) => 0 /* After red */
+ | Black(x) => 0 /* After black */
+ | Green(x) => 0; /* After second green */ /* On next line after blahCurriedX def */
let name_equal = (x, y) => {
x == y;
};
-let equal = (i1, i2) =>
- i1.contents === i2.contents && true; /* most unlikely first */
+let equal = (i1, i2) => i1.contents
+ === i2.contents
+ && true; /* most unlikely first */
-let equal = (i1, i2) =>
- compare(compare(0, 0), compare(1, 1)); /* END OF LINE HERE */
+let equal = (i1, i2) => compare(
+ compare(0, 0),
+ compare(1, 1),
+); /* END OF LINE HERE */
let tuple_equal = ((i1, i2)) => i1 == i2;
-let tuple_equal = ((csu, mgd)) =>
- /* Some really long comments, see https://github.com/facebook/reason/issues/811 */
- tuple_equal((csu, mgd));
+let tuple_equal = ((csu, mgd)) => /* Some really long comments, see https://github.com/facebook/reason/issues/811 */
+ tuple_equal((
+ csu,
+ mgd,
+ ));
/** Comments inside empty function bodies
* See https://github.com/facebook/reason/issues/860
@@ -580,35 +571,35 @@ ignore((_xxx, _yyy) => {
/* Closing comment */
});
-type tester('a, 'b) =
- | TwoArgsConstructor('a, 'b)
- | OneTupleArgConstructor(('a, 'b));
+type tester('a, 'b) = | TwoArgsConstructor(
+ 'a,
+ 'b,
+ )
+ | OneTupleArgConstructor(
+ ('a, 'b),
+ );
let callFunctionTwoArgs = (a, b) => ();
let callFunctionOneTuple = tuple => ();
-let y =
- TwoArgsConstructor(
- 1, /*eol1*/
- 2 /* eol2 */
- );
+let y = TwoArgsConstructor(
+ 1, /*eol1*/
+ 2 /* eol2 */
+);
-let y =
- callFunctionTwoArgs(
- 1, /*eol1*/
- 2 /* eol2 */
- );
+let y = callFunctionTwoArgs(
+ 1, /*eol1*/
+ 2 /* eol2 */
+);
-let y =
- OneTupleArgConstructor((
- 1, /*eol1*/
- 2 /* eol2 */
- ));
+let y = OneTupleArgConstructor((
+ 1, /*eol1*/
+ 2 /* eol2 */
+));
-let y =
- callFunctionOneTuple((
- 1, /*eol1*/
- 2 /* eol2 */
- ));
+let y = callFunctionOneTuple((
+ 1, /*eol1*/
+ 2 /* eol2 */
+));
type polyRecord('a, 'b) = {
fieldOne: 'a,
@@ -625,29 +616,25 @@ let r = {
fieldTwo: 2 /* eol2 with trailing comma */
};
-let y =
- TwoArgsConstructor(
- "1", /*eol1*/
- "2" /* eol2 */
- );
+let y = TwoArgsConstructor(
+ "1", /*eol1*/
+ "2" /* eol2 */
+);
-let y =
- callFunctionTwoArgs(
- "1", /*eol1*/
- "2" /* eol2 */
- );
+let y = callFunctionTwoArgs(
+ "1", /*eol1*/
+ "2" /* eol2 */
+);
-let y =
- OneTupleArgConstructor((
- "1", /*eol1*/
- "2" /* eol2 */
- ));
+let y = OneTupleArgConstructor((
+ "1", /*eol1*/
+ "2" /* eol2 */
+));
-let y =
- callFunctionOneTuple((
- "1", /*eol1*/
- "2" /* eol2 */
- ));
+let y = callFunctionOneTuple((
+ "1", /*eol1*/
+ "2" /* eol2 */
+));
let r = {
fieldOne: "1", /*eol1*/
@@ -661,29 +648,25 @@ let r = {
let identifier = "hello";
-let y =
- TwoArgsConstructor(
- identifier, /*eol1*/
- identifier /* eol2 */
- );
+let y = TwoArgsConstructor(
+ identifier, /*eol1*/
+ identifier /* eol2 */
+);
-let y =
- callFunctionTwoArgs(
- identifier, /*eol1*/
- identifier /* eol2 */
- );
+let y = callFunctionTwoArgs(
+ identifier, /*eol1*/
+ identifier /* eol2 */
+);
-let y =
- OneTupleArgConstructor((
- identifier, /*eol1*/
- identifier /* eol2 */
- ));
+let y = OneTupleArgConstructor((
+ identifier, /*eol1*/
+ identifier /* eol2 */
+));
-let y =
- callFunctionOneTuple((
- identifier, /*eol1*/
- identifier /* eol2 */
- ));
+let y = callFunctionOneTuple((
+ identifier, /*eol1*/
+ identifier /* eol2 */
+));
let r = {
fieldOne: identifier, /*eol1*/
@@ -695,29 +678,25 @@ let r = {
fieldTwo: identifier /* eol2 with trailing comma */
};
-let y =
- TwoArgsConstructor(
- identifier: string, /*eol1*/
- identifier: string /* eol2 */
- );
+let y = TwoArgsConstructor(
+ identifier: string, /*eol1*/
+ identifier: string /* eol2 */
+);
-let y =
- callFunctionTwoArgs(
- identifier: string, /*eol1*/
- identifier: string /* eol2 */
- );
+let y = callFunctionTwoArgs(
+ identifier: string, /*eol1*/
+ identifier: string /* eol2 */
+);
+
+let y = OneTupleArgConstructor((
+ identifier: string, /*eol1*/
+ identifier: string /* eol2 */
+));
-let y =
- OneTupleArgConstructor((
- identifier: string, /*eol1*/
- identifier: string /* eol2 */
- ));
-
-let y =
- callFunctionOneTuple((
- identifier: string, /*eol1*/
- identifier: string /* eol2 */
- ));
+let y = callFunctionOneTuple((
+ identifier: string, /*eol1*/
+ identifier: string /* eol2 */
+));
let r = {
fieldOne: (identifier: string), /*eol1*/
diff --git a/formatTest/typeCheckedTests/expected_output/specificMLSyntax.4.04.0.re b/formatTest/typeCheckedTests/expected_output/specificMLSyntax.4.04.0.re
index 6cc7f92c8..1372355fc 100644
--- a/formatTest/typeCheckedTests/expected_output/specificMLSyntax.4.04.0.re
+++ b/formatTest/typeCheckedTests/expected_output/specificMLSyntax.4.04.0.re
@@ -4,10 +4,9 @@ module Foo = {
let foo = (Foo.{name}) => ();
-let f =
- fun
- | Foo.{name} => ()
- | _ => ();
+let f = fun
+ | Foo.{name} => ()
+ | _ => ();
let x = {Foo.name: "Reason"};
let Foo.{name} = x;
diff --git a/formatTest/typeCheckedTests/expected_output/trailing.re b/formatTest/typeCheckedTests/expected_output/trailing.re
index 67833739a..deecec27e 100644
--- a/formatTest/typeCheckedTests/expected_output/trailing.re
+++ b/formatTest/typeCheckedTests/expected_output/trailing.re
@@ -41,10 +41,8 @@ let (i, j) = myTuple;
type foo_('a, 'b) = ('a, 'b);
type foo__ = foo_(int, int);
-type foo('a, 'b) =
- | Foo('a, 'b);
-type tupVariant('a, 'b) =
- | Tup(('a, 'b));
+type foo('a, 'b) = | Foo('a, 'b);
+type tupVariant('a, 'b) = | Tup(('a, 'b));
/* Won't wrap so removes trailing comma */
let noWrap = (a, b) => {
@@ -55,11 +53,10 @@ let noWrap = (a, b) => {
let res = noWrap(0, 0);
let reallyLongIdentifierCausesWrap = 0;
let wrap = noWrap;
-let res =
- wrap(
- reallyLongIdentifierCausesWrap,
- reallyLongIdentifierCausesWrap,
- );
+let res = wrap(
+ reallyLongIdentifierCausesWrap,
+ reallyLongIdentifierCausesWrap,
+);
/* Won't wrap so removes trailing comma */
let noWrap = (~a, ~b) => {
@@ -73,12 +70,11 @@ let noWrap = (~a=0, ~b=0, ()) => {
x + x;
};
-let res =
- noWrap(
- ~a=reallyLongIdentifierCausesWrap,
- ~b=reallyLongIdentifierCausesWrap,
- (),
- );
+let res = noWrap(
+ ~a=reallyLongIdentifierCausesWrap,
+ ~b=reallyLongIdentifierCausesWrap,
+ (),
+);
/* Won't wrap so removes trailing comma */
let noWrap = (~a=0, ~b: int=0, ()) => {
@@ -86,12 +82,11 @@ let noWrap = (~a=0, ~b: int=0, ()) => {
x + x;
};
-let res =
- noWrap(
- ~a=reallyLongIdentifierCausesWrap,
- ~b=reallyLongIdentifierCausesWrap,
- (),
- );
+let res = noWrap(
+ ~a=reallyLongIdentifierCausesWrap,
+ ~b=reallyLongIdentifierCausesWrap,
+ (),
+);
/* Long enough to wrap the args and therefore remove trail */
let wrap = (long, enough, toWrap, args) => {
@@ -103,11 +98,10 @@ let takesPattern = (d, Foo(x, y)) => {
/* won't wrap */
let _ = Foo(y, x);
/* will wrap */
- let ret =
- Foo(
- y + y + y + y,
- x + x + x + x + x + x + x + x + x,
- );
+ let ret = Foo(
+ y + y + y + y,
+ x + x + x + x + x + x + x + x + x,
+ );
ret;
};
@@ -115,11 +109,10 @@ let takesPattern = (d, Tup((x, y))) => {
/* won't wrap */
let _ = Tup((y, x));
/* will wrap */
- let ret =
- Tup((
- y + y + y + y,
- x + x + x + x + x + x + x + x + x,
- ));
+ let ret = Tup((
+ y + y + y + y,
+ x + x + x + x + x + x + x + x + x,
+ ));
ret;
};
@@ -134,19 +127,17 @@ let takesPattern =
/* won't wrap */
let _ = Tup((d, d));
/* will wrap */
- let ret =
- Tup((
- d + d + d + d,
- d + d + d + d + d + d + d + d + d,
- ));
+ let ret = Tup((
+ d + d + d + d,
+ d + d + d + d + d + d + d + d + d,
+ ));
ret;
};
let myFunc = (type t, ()) => ();
type funcType = (int, int) => int;
-type v =
- | Func((int, int) => int);
+type v = | Func((int, int) => int);
type params('a, 'b) = ('a, 'b);
@@ -161,13 +152,12 @@ class virtual
'anotherReallyLongIdentifier,
)
(init, init2) = {
- val mutable v:
- list(
- (
- 'reallyLongIdentifier,
- 'anotherReallyLongIdentifier,
- ),
- ) = [
+ val mutable v: list(
+ (
+ 'reallyLongIdentifier,
+ 'anotherReallyLongIdentifier,
+ ),
+ ) = [
(init, init2),
];
pub virtual implementMe:
@@ -183,16 +173,15 @@ class extendedStack
'anotherReallyLongIdentifier,
)
(init, init2) = {
- inherit
- (
- class tupleStack(
- 'reallyLongIdentifier,
- 'anotherReallyLongIdentifier,
- )
- )(
- init,
- init2,
- );
+ inherit (
+ class tupleStack(
+ 'reallyLongIdentifier,
+ 'anotherReallyLongIdentifier,
+ )
+ )(
+ init,
+ init2,
+ );
pub implementMe = (i, j) => (i, j);
};
@@ -205,17 +194,16 @@ module type ReallyReallyReallyLongIdentifierModuleType = {
type t;
};
module type F = (HasType) => HasType2;
-module FInstance = (HasType: HasType) => {
+module FInstance = (HasType : HasType) => {
type t = HasType.t;
type q = HasType.t;
};
module ReallyReallyReallyLongIdentifierModuleName = {
type t = int;
};
-module FResult =
- FInstance(
- ReallyReallyReallyLongIdentifierModuleName,
- );
+module FResult = FInstance(
+ ReallyReallyReallyLongIdentifierModuleName,
+);
module Component = {
let createElement = (~arg, ~children, ()) => [
diff --git a/src/reason-parser/reason_pprint_ast.ml b/src/reason-parser/reason_pprint_ast.ml
index 4cee9fd14..f446c48e0 100644
--- a/src/reason-parser/reason_pprint_ast.ml
+++ b/src/reason-parser/reason_pprint_ast.ml
@@ -131,7 +131,14 @@ and tokenFixity =
(* Such as !simple_expr and ~!simple_expr. These function applications are
considered *almost* "simple" because they may be allowed anywhere a simple
expression is accepted, except for when on the left hand side of a
- dot/send. *)
+ dot/send. It would be better to refer to the "level" of simplicity (aka
+ precedence level).
+ - dot level precedence (highest, including send)
+ - prefix level precedence (mid)
+ - application level precedence (such as x(y))
+ - infix level precedence: (multiple levels within this one)
+ - sequence level precedence ( such as the commas in (x, y) and [x, y])
+ *)
| AlmostSimplePrefix of string
| UnaryPlusPrefix of string
| UnaryMinusPrefix of string
@@ -1933,31 +1940,31 @@ let formatAttachmentApplication finalWrapping (attachTo: (bool * Layout.t) optio
match (appTermItems, attachTo) with
| ([], _) -> raise (NotPossible "No app terms")
| ([hd], None) -> source_map ?loc hd
- | ([hd], (Some (useSpace, toThis))) -> label ~space:useSpace toThis (source_map ?loc hd)
+ | ([hd], (Some (useSpace, toThis))) -> label ~break:`Never ~space:useSpace toThis (source_map ?loc hd)
| (hd::tl, None) ->
source_map ?loc (formatIndentedApplication hd tl)
| (hd::tl, (Some (useSpace, toThis))) ->
label
- ~space:useSpace
+ ~break:`Never ~space:useSpace
toThis
(source_map ?loc (formatIndentedApplication hd tl))
)
| Some (attachedList, wrappedListy) -> (
match (attachedList, attachTo) with
| ([], Some (useSpace, toThis)) ->
- label ~space:useSpace toThis (source_map ?loc wrappedListy)
+ label ~break:`Never ~space:useSpace toThis (source_map ?loc wrappedListy)
| ([], None) ->
(* Not Sure when this would happen *)
source_map ?loc wrappedListy
| (_::_, Some (useSpace, toThis)) ->
(* TODO: Can't attach location to this - maybe rewrite anyways *)
let attachedArgs = makeAppList attachedList in
- label ~space:useSpace toThis
- (label ~space:true attachedArgs wrappedListy)
+ label ~break:`Never ~space:useSpace toThis
+ (label ~break:`Never ~space:true attachedArgs wrappedListy)
| (_::_, None) ->
(* Args that are "attached to nothing" *)
let appList = makeAppList attachedList in
- source_map ?loc (label ~space:true appList wrappedListy)
+ source_map ?loc (label ~break:`Never ~space:true appList wrappedListy)
)
(*
@@ -2985,7 +2992,7 @@ let printer = object(self:'self)
(Ptype_variant _, _, Some _)} *)
| (Ptype_variant lst, scope, Some mani) -> [
[self#core_type mani];
- let variant = makeList ~break:IfNeed ~postSpace:true ~inline:(true, true) (self#type_variant_list lst) in
+ let variant = makeList ~break:IfNeed ~postSpace:true ~inline:(true, false) (self#type_variant_list lst) in
privatize scope [variant];
]
@@ -4246,7 +4253,7 @@ let printer = object(self:'self)
let rightItm = self#unparseResolvedRule (
self#ensureContainingRule ~withPrecedence:prec ~reducesAfterRight:rightExpr ()
) in
- let expr = label ~space:forceSpace (atom printedIdent) rightItm in
+ let expr = label ~break:`Never ~space:forceSpace (atom printedIdent) rightItm in
SpecificInfixPrecedence ({reducePrecedence=prec; shiftPrecedence=Token printedIdent}, LayoutNode expr)
(* Will need to be rendered in self#expression as (~-) x y z. *)
| (_, _) ->
@@ -4852,7 +4859,7 @@ let printer = object(self:'self)
| None -> letPattern
| Some tc -> formatTypeConstraint letPattern tc
in
- let includingEqual = makeList ~postSpace:true [upUntilEqual; atom "="] in
+ let includingEqual = label ~space:true ~break:`Never upUntilEqual (atom "=") in
formatAttachmentApplication applicationFinalWrapping (Some (true, includingEqual)) appTerms
(*
@@ -5071,7 +5078,7 @@ let printer = object(self:'self)
let firstOne =
match mt with
| None -> atom "()"
- | Some mt' -> self#module_type (makeList [atom s.txt; atom ":"]) mt'
+ | Some mt' -> self#module_type (label ~space: true (atom s.txt) (atom ":")) mt'
in
let (functorArgsRecurse, returnStructure) = (self#curriedFunctorPatternsAndReturnStruct me2) in
(firstOne::functorArgsRecurse, returnStructure)
@@ -5169,13 +5176,10 @@ let printer = object(self:'self)
...
}
*)
- method wrappedBinding prefixText ~arrow pattern patternAux expr =
+ method wrappedBinding prefixText ~arrow pattern expr =
let expr = self#process_underscore_application expr in
let (argsList, return) = self#curriedPatternsAndReturnVal expr in
- let patternList = match patternAux with
- | [] -> pattern
- | _::_ -> makeList ~postSpace:true ~inline:(true, true) ~break:IfNeed (pattern::patternAux)
- in
+ let patternList = pattern in
match (argsList, return.pexp_desc) with
| ([], Pexp_constraint (e, ct)) ->
let typeLayout =
@@ -5196,12 +5200,12 @@ let printer = object(self:'self)
self#formatSimplePatternBinding prefixText patternList None appTerms
| (_::_, _) ->
let (argsWithConstraint, actualReturn) = self#normalizeFunctionArgsConstraint argsList return in
- let fauxArgs =
- List.concat [patternAux; argsWithConstraint] in
+ let fauxArgs = argsWithConstraint in
let returnedAppTerms = self#unparseExprApplicationItems actualReturn in
(* Attaches the `=` to `f` to recreate javascript function syntax in
* let f = (a, b) => a + b; *)
- let lbl = makeList ~sep:(Sep " ") ~break:Layout.Never [pattern; atom "="] in
+ (* TRY A LABEL BREAK NEVER PSACE TRUE HERE *)
+ let lbl = label ~space:true ~break:`Never pattern (atom "=") in
self#wrapCurriedFunctionBinding prefixText ~arrow lbl fauxArgs returnedAppTerms
(* Similar to the above method. *)
@@ -5291,7 +5295,7 @@ let printer = object(self:'self)
| [], (Ppat_var _) ->
self#wrappedBinding prefixText ~arrow:"=>"
(source_map ~loc:pat.ppat_loc (self#simple_pattern pat))
- [] expr
+ expr
(*
Ppat_constraint is used in bindings of the form
@@ -5912,7 +5916,7 @@ let printer = object(self:'self)
switchWith
(source_map ~loc:estimatedBracePoint
(makeList ~indent:settings.trySwitchIndent ~wrap:("{", "}")
- ~break:Always_rec ~postSpace:true cases))
+ ~break:IfNeed ~postSpace:true cases))
in
Some lbl
| Pexp_ifthenelse (e1, e2, eo) ->
@@ -6952,9 +6956,7 @@ let printer = object(self:'self)
(makeList ~postSpace:true ~inline:(false, true) ~break:IfNeed privateVirtualName) in
label ~space:true (atom "pri") openingTokens
| Public ->
- let virtualName = [atom "virtual"; atom s.txt] in
- let openingTokens =
- (makeList ~postSpace:true ~inline:(false, true) ~break:IfNeed virtualName) in
+ let openingTokens = label ~space:true (atom "virtual") (atom s.txt) in
label ~space:true (atom "pub") openingTokens
in
formatTypeConstraint opening (self#core_type ct)
@@ -7004,7 +7006,7 @@ let printer = object(self:'self)
(self#unparseExprApplicationItems e)
(* This form means that there is no type constraint - it's a strange node name.*)
| Pexp_poly (e, None) ->
- self#wrappedBinding methodText ~arrow:"=>" (atom s.txt) [] e
+ self#wrappedBinding methodText ~arrow:"=>" (atom s.txt) e
| _ -> failwith "Concrete methods should only ever have Pexp_poly."
)
| Pcf_constraint (ct1, ct2) ->
diff --git a/src/reason-parser/vendor/easy_format/vendored_easy_format.ml b/src/reason-parser/vendor/easy_format/vendored_easy_format.ml
index 3f9a5b902..53e9bd5e0 100644
--- a/src/reason-parser/vendor/easy_format/vendored_easy_format.ml
+++ b/src/reason-parser/vendor/easy_format/vendored_easy_format.ml
@@ -1,5 +1,108 @@
open Format
+(**
+
+Input:
+
+ --b--b--
+
+hbox (always):
+
+ --b--b--
+
+vbox (always):
+
+ --b
+ --b
+ --
+
+within a “hv” box (only if not enough room):
+
+ ---b
+ ---b
+ ---
+
+ALSO:
+
+
+hov_box (packing) (only if not enough room):
+
+ ---b---b
+ ---
+
+ Also: If input: [(---[(----[(---b)]b)]b)]
+
+ (---
+ (----
+ (---)))
+
+box (structural) (only if not enough room):
+
+ ---b---b
+ ---
+
+ But the difference from hov_box is:
+ If input: [(---[(----[(---b)]b)]b)]
+
+ (---
+ (----
+ (---
+ )
+ )
+ )
+
+
+ NOTE: open_hvbox breaks every breakhint in the immediate box but only if
+ necessary, and for labels that would only be one breakhing (usually).
+
+ lbl (lbl (lbl A B) C) D
+
+
+
+ -------R-------------
+ lbl(L, lbl(lbl(RLL, RLR), RR))
+ -----RL------
+
+ (Assume break `Auto)
+ Without the joinFollowingLabel property on A, you would end up doing:
+
+ open_hovbox
+
+ (* For L *)
+ + pp_open_hvbox fmt 0;
+ | fprint_t fmt L;
+ | pp_print_break;
+ | fprint_t fmt R;
+ | + pp_open_hvbox fmt 0;
+ | | fprint_t fmt RL;
+ | | + pp_open_hvbox fmt 0
+ | | |
+ | | |
+ | | |
+ | | +
+ | | pp_print_break;
+ | | fprint_t fmt RR;
+ | |
+ | + pp_close_box fmt ()
+ |
+ + pp_close_box fmt ()
+
+ Or, with the hvbox syntax:
+
+ [L
[[[RLL
RLR], RR]]]
+
+ In other words, every label is wrapped in a box which makes it impossible for
+ labels to group together on the same line with high priority.
+ The joinFollowingLabel property on the outermost label would turn the boxes
+ into (still hov_boxes)
+
+ [[[[L
RLL
RLR], RR]]]
+
+ Or more simply:
+
+ [[L
RLL
RLR], RR]
+*)
+
(** Shadow map and split with tailrecursive variants. *)
module List = struct
include List
@@ -344,7 +447,13 @@ struct
pp_print_string fmt s;
(pp_close_tag [@warning "-3"]) fmt ()
- let rec fprint_t fmt = function
+ let rec fprint_t fmt x = match x with
+ Label (label_left, x) -> fprint_t_join_labels ~rev_label_lefts:[label_left] fmt x
+ | Atom _
+ | List _
+ | Custom _ -> fprint_t_labels_already_joined fmt x
+
+ and fprint_t_labels_already_joined fmt = function
Atom (s, p) ->
tag_string fmt p.atom_style s;
@@ -355,10 +464,19 @@ struct
else
fprint_list2 fmt param l;
close_tag fmt p.list_style
-
- | Label (label, x) -> fprint_pair fmt label x
+ | Label (label_left, x) -> fprint_pair fmt label_left x
| Custom f -> f fmt
+
+ and fprint_t_join_labels ~rev_label_lefts fmt right = match right with
+ | Label (label_left, right) -> fprint_t_join_labels ~rev_label_lefts:(label_left :: rev_label_lefts) fmt right
+ | Atom (_, _)
+ | List ((_, _, _, _), _)
+ | Custom _ ->
+ let compressed_labels = compress_labels ~rev_label_lefts right in
+ fprint_t_labels_already_joined fmt compressed_labels
+
+
and fprint_list_body_stick_left fmt p sep hd tl =
open_tag fmt p.body_style;
fprint_t fmt hd;
@@ -396,6 +514,7 @@ struct
| Some (lab, lp) ->
open_tag fmt lp.label_style;
fprint_t fmt lab;
+ (* pp_print_string fmt (String.make 1 ','); *)
close_tag fmt lp.label_style;
if lp.space_after_label then
pp_print_string fmt " "
@@ -403,18 +522,22 @@ struct
(* Either horizontal or vertical list *)
and fprint_list fmt label ((op, sep, cl, p) as param) = function
[] ->
+ (* pp_print_string fmt (String.make 1 '<'); *)
fprint_opt_label fmt label;
tag_string fmt p.opening_style op;
if p.space_after_opening || p.space_before_closing then
pp_print_string fmt " ";
tag_string fmt p.closing_style cl
+ (* pp_print_string fmt (String.make 1 '<') *)
| hd :: tl as l ->
- if tl = [] || p.separators_stick_left then
+ (* pp_print_string fmt (String.make 1 '<'); *)
+ (if tl = [] || p.separators_stick_left then
fprint_list_stick_left fmt label param hd tl l
else
- fprint_list_stick_right fmt label param hd tl l
+ fprint_list_stick_right fmt label param hd tl l)
+ (* pp_print_string fmt (String.make 1 '>'); *)
and fprint_list_stick_left fmt label (op, sep, cl, p) hd tl l =
@@ -442,6 +565,7 @@ struct
pp_close_box fmt ()
and fprint_list_stick_right fmt label (op, sep, cl, p) hd tl l =
+ (* pp_print_string fmt (String.make 1 '['); *)
let base_indent = p.indent_body in
let sep_indent =
String.length sep + (if p.space_after_separator then 1 else 0)
@@ -482,6 +606,7 @@ struct
pp_print_break fmt 0 (-indent);
tag_string fmt p.closing_style cl;
pp_close_box fmt ()
+ (* pp_print_string fmt (String.make 1 ']'); *)
@@ -519,13 +644,14 @@ struct
and fprint_pair fmt ((lab, lp) as label) x =
match x with
List ((op, sep, cl, p), l) when p.stick_to_label && p.align_closing ->
- fprint_list fmt (Some label) (op, sep, cl, p) l
+ fprint_list fmt (Some label) (op, sep, cl, p) l;
| _ ->
let indent = lp.indent_after_label in
pp_open_hvbox fmt 0;
open_tag fmt lp.label_style;
+ (* pp_print_string fmt (String.make 1 '<'); *)
fprint_t fmt lab;
close_tag fmt lp.label_style;
@@ -545,8 +671,71 @@ struct
else
()
);
+ (* pp_print_string fmt (String.make 1 ','); *)
fprint_t fmt x;
pp_close_box fmt ()
+ (* pp_print_string fmt (String.make 1 '>') *)
+
+ (*
+ Rewrites labels of the following:
+
+ (y, (z, q))
+
+ Into:
+
+ ((y, z), q)
+
+ Rewrites labels of the following:
+
+ (x, (y, (z, q))
+
+ Into:
+
+ (((x, y), z), q)
+
+ Where x, y, and z are all left elements of labels.
+ (z, q)'s original break/space config is transfered to the outermost label,
+ (y, ...)'s break/space config is transfered to ((x, y), ...)'s and so on.
+
+ Computes the list (z :: y :: x) along with q
+
+ We create a new Label next:
+
+ Label(
+ (
+ Label(
+ (
+ ...,
+ (y, (..))'s original params
+ ),
+ z
+ ),
+ (z,q)'s original params
+ ),
+ q
+ )
+
+
+ Even traverses deeply left to accomplish the same:
+
+ Rewrites labels of the following:
+
+ (x, (((q, r), s), (z, q)))
+
+ Into:
+
+ (x, (((q, r), s), (z, q)))
+
+
+ *)
+ and compress_labels ~rev_label_lefts right =
+ match rev_label_lefts with
+ | [] -> right
+ | (last_left_content, left_param) :: tl ->
+ Label(
+ ((compress_labels ~rev_label_lefts:tl last_left_content), left_param),
+ right
+ )
let to_formatter fmt x =
let x = rewrite x in