Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Slightly better breaking of unary prefix symbols. #2388

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .ci/esy-build-steps.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,7 @@ steps:
- template: utils/publish-build-cache.yml
- script: esy x refmt --version
displayName: 'esy x refmt --version'
- script: esy make test
displayName: 'esy make test'
# Run tests or any additional steps here
# - script: esy b dune runtest
2 changes: 1 addition & 1 deletion formatTest/errorTests/expected_output/syntaxError.re
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
File "syntaxError.re", line 1, characters 9-10:
Error: File "syntaxError.re", line 1, characters 9-10:
Error: Syntax error
Error: Syntax error
3 changes: 3 additions & 0 deletions formatTest/errorTests/expected_output/syntaxError.re.4.06.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
File "syntaxError.re", line 1, characters 9-10:
Error: File "syntaxError.re", line 1, characters 9-10:
Error: Syntax error
2 changes: 2 additions & 0 deletions formatTest/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ VERBOSE=${VERBOSE:-}
OCAML_VERSION=`echo $(ocaml -version) | egrep -o '[0-9]+.[0-9]+.[0-9]+' | head -1`
OCAML_VERSION=${OCAML_VERSION:-"4.02.3"}

echo "Testing with OCaml Version: $OCAML_VERSION"

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

REFMT="$DIR/../_build/install/default/bin/refmt"
Expand Down
88 changes: 88 additions & 0 deletions formatTest/typeCheckedTests/expected_output/unary.re
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
type result('a, 'b) =
| Ok('a)
| Error('b);

let returnsAResultToBeUnwrapped = (a, b, c) =>
switch (a, b, c) {
| (None, Some(i), Some(j)) => Ok((i, j))
| (Some(i), Some(j), None) =>
Ok(("hi", "bye"))
| _ =>
Error(
Invalid_argument(
"This is not a valid argument",
),
)
};

let returnsAnIntegerResultNotWrapped = (a, b, c) =>
switch (a, b, c) {
| (None, Some(i), Some(j)) => 0
| (Some(i), Some(j), None) => (-1)
| _ => 100
};

let returnsABoolReturnValueNoResult = (a, b, c) =>
switch (a, b, c) {
| (None, Some(i), Some(j)) => true
| (Some(i), Some(j), None) => false
| _ => false
};

let (!!) = res =>
switch (res) {
| Ok(o) => o
| Error(e) => raise(e)
};

let result =
!!returnsAResultToBeUnwrapped(
Some(
"this realy long string will make things wrap",
),
Some(
"this realy long string will make things wrap",
),
Some(
"this realy long string will make things wrap",
),
);

let result =
- returnsAnIntegerResultNotWrapped(
Some(
"this realy long string will make things wrap",
),
Some(
"this realy long string will make things wrap",
),
Some(
"this realy long string will make things wrap",
),
);

let result =
+ returnsAnIntegerResultNotWrapped(
Some(
"this realy long string will make things wrap",
),
Some(
"this realy long string will make things wrap",
),
Some(
"this realy long string will make things wrap",
),
);

let result =
!returnsABoolReturnValueNoResult(
Some(
"this realy long string will make things wrap",
),
Some(
"this realy long string will make things wrap",
),
Some(
"this realy long string will make things wrap",
),
);
51 changes: 51 additions & 0 deletions formatTest/typeCheckedTests/input/unary.re
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@


type result('a, 'b) = Ok('a) | Error('b);

let returnsAResultToBeUnwrapped = (a, b, c) => switch(a, b, c) {
| (None, Some(i), Some(j)) => Ok((i, j));
| (Some(i), Some(j), None) => Ok(("hi", "bye"));
| _ => Error(Invalid_argument("This is not a valid argument"))
};

let returnsAnIntegerResultNotWrapped = (a, b, c) => switch(a,b, c) {
| (None, Some(i), Some(j)) => 0
| (Some(i), Some(j), None) => -1
| _ => 100
};

let returnsABoolReturnValueNoResult = (a, b, c) => switch(a,b, c) {
| (None, Some(i), Some(j)) => true
| (Some(i), Some(j), None) => false
| _ => false
};

let (!!) = res => switch(res) {
| Ok(o) => o
| Error(e) => raise(e)
};


let result = !!returnsAResultToBeUnwrapped(
Some("this realy long string will make things wrap"),
Some("this realy long string will make things wrap"),
Some("this realy long string will make things wrap")
);

let result = -returnsAnIntegerResultNotWrapped(
Some("this realy long string will make things wrap"),
Some("this realy long string will make things wrap"),
Some("this realy long string will make things wrap")
)

let result = +returnsAnIntegerResultNotWrapped(
Some("this realy long string will make things wrap"),
Some("this realy long string will make things wrap"),
Some("this realy long string will make things wrap")
)

let result = !returnsABoolReturnValueNoResult(
Some("this realy long string will make things wrap"),
Some("this realy long string will make things wrap"),
Some("this realy long string will make things wrap")
);
6 changes: 3 additions & 3 deletions src/reason-parser/reason_pprint_ast.ml
Original file line number Diff line number Diff line change
Expand Up @@ -4068,7 +4068,7 @@ let printer = object(self:'self)
self#ensureContainingRule ~withPrecedence:prec ~reducesAfterRight:rightExpr ()
) in
SpecificInfixPrecedence
({reducePrecedence=prec; shiftPrecedence = prec}, LayoutNode (label ~space:forceSpace (atom prefixStr) rightItm))
({reducePrecedence=prec; shiftPrecedence = prec}, LayoutNode (label ~indent:0 ~break:`Never ~space:forceSpace (atom prefixStr) rightItm))
| (UnaryPostfix postfixStr, [(Nolabel, leftExpr)]) ->
let forceSpace = match leftExpr.pexp_desc with
| Pexp_apply (ee, _) ->
Expand Down Expand Up @@ -4118,7 +4118,7 @@ let printer = object(self:'self)
let rightItm = self#unparseResolvedRule (
self#ensureContainingRule ~withPrecedence:prec ~reducesAfterRight:rightExpr ()
) in
let expr = label ~space:true (atom printedIdent) rightItm in
let expr = label ~indent:0 ~break:`Never ~space:true (atom printedIdent) rightItm in
SpecificInfixPrecedence ({reducePrecedence=prec; shiftPrecedence=Token printedIdent}, LayoutNode expr)
| (UnaryMinusPrefix printedIdent as x, [(Nolabel, rightExpr)])
| (UnaryNotPrefix printedIdent as x, [(Nolabel, rightExpr)]) ->
Expand All @@ -4133,7 +4133,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 ~indent:0 ~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. *)
| (_, _) ->
Expand Down