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

WIP: Operator escaping #1221

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
14 changes: 7 additions & 7 deletions formatTest/typeCheckedTests/expected_output/attributes.re
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,15 @@ let x = "hello" [@onHello];

let x = "hello" [@onHello];

let x = "hello" ^ "goodbye" [@onGoodbye];
let x = "hello" ++ "goodbye" [@onGoodbye];

let x = "hello" [@onHello] ^ "goodbye";
let x = "hello" [@onHello] ++ "goodbye";

let x = "hello" [@onHello] ^ "goodbye";
let x = "hello" [@onHello] ++ "goodbye";

let x = "hello" ^ "goodbye" [@onGoodbye];
let x = "hello" ++ "goodbye" [@onGoodbye];

let x = ("hello" ^ "goodbye") [@onEverything];
let x = ("hello" ++ "goodbye") [@onEverything];

let x = 10 + 20 [@on20];

Expand Down Expand Up @@ -148,11 +148,11 @@ let x = (- add thisVal thisVal) [@onEverything];
let bothTrue x y => {contents: x && y};

let something =
!(bothTrue true true)
(bothTrue true true)^
[@onEverythingToRightOfEquals];

let something =
!(bothTrue true true [@onlyOnArgumentToBang]);
(bothTrue true true [@onlyOnArgumentToBang])^;

let res =
add 2 4 [@appliesToEntireFunctionApplication];
Expand Down
2 changes: 1 addition & 1 deletion formatTest/typeCheckedTests/expected_output/basics.re
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ let reasonDoubleBarNestedAnyPatterns =

let (\+) = (+);

let a = 2.0 *\* 4.0;
let a = 2.0 ** 4.0;

let (\===) = (===);

Expand Down
4 changes: 2 additions & 2 deletions formatTest/typeCheckedTests/expected_output/comments.re
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,10 @@ module Temp = {

let store_attributes arg => {
let attributes_file = "test";
let proc_name = attributes_file ^ ".proc";
let proc_name = attributes_file ++ ".proc";
let should_write =
/* only overwrite defined procedures */
Temp.v || not Temp.v;
Temp.v || !Temp.v;
if should_write {
Temp.logIt proc_name ()
}
Expand Down
4 changes: 2 additions & 2 deletions formatTest/typeCheckedTests/expected_output/jsx.re
Original file line number Diff line number Diff line change
Expand Up @@ -185,15 +185,15 @@ let (><) a b => a + b;

let (/>) a b => a + b;

let (><\/) a b => a + b;
let (></) a b => a + b;

let tag1 = 5 />< 6;

let tag2 = 5 >< 7;

let tag3 = 5 /> 7;

let tag4 = 5 ><\/ 7;
let tag4 = 5 ></ 7;

let b = 2;

Expand Down
16 changes: 8 additions & 8 deletions formatTest/typeCheckedTests/input/attributes.re
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ let thisInst : myType =
let x = ("hello" [@onHello]);
let x = "hello" [@onHello];

let x = "hello" ^ ("goodbye" [@onGoodbye]);
let x = ("hello" [@onHello]) ^ "goodbye";
let x = "hello" [@onHello] ^ "goodbye";
let x = "hello" ^ "goodbye" [@onGoodbye];
let x = ("hello" ^ "goodbye") [@onEverything];
let x = "hello" ++ ("goodbye" [@onGoodbye]);
let x = ("hello" [@onHello]) ++ "goodbye";
let x = "hello" [@onHello] ++ "goodbye";
let x = "hello" ++ "goodbye" [@onGoodbye];
let x = ("hello" ++ "goodbye") [@onEverything];

let x = 10 + (20 [@on20]);
let x = 10 + 20 [@on20];
Expand Down Expand Up @@ -106,8 +106,8 @@ let x = (- add thisVal thisVal) [@onEverything];


let bothTrue x y => {contents: x && y};
let something = !(bothTrue true true) [@onEverythingToRightOfEquals];
let something = !(bothTrue true true [@onlyOnArgumentToBang]);
let something = (bothTrue true true)^ [@onEverythingToRightOfEquals];
let something = (bothTrue true true [@onlyOnArgumentToBang])^;

let res = add 2 4 [@appliesToEntireFunctionApplication];
add 2 4 [@appliesToEntireFunctionApplication];
Expand Down Expand Up @@ -301,4 +301,4 @@ external createCompositeElementInternalHack : reactClass =>

external add_nat: int => int => int = "add_nat_bytecode" "add_nat_native";

external foo : bool => bool = "" [@@bs.module "Bar"] [@@ocaml.deprecated "Use bar instead. It's a much cooler function. This string needs to be a little long"];
external foo : bool => bool = "" [@@bs.module "Bar"] [@@ocaml.deprecated "Use bar instead. It's a much cooler function. This string needs to be a little long"];
40 changes: 20 additions & 20 deletions formatTest/unit_tests/expected_output/basicStructures.re
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ for i in
}
};

let x = !(! !foo).bar;
let x = !(!(!foo)).bar;

let x = !foo.bar;

Expand All @@ -44,15 +44,15 @@ let x = !(!foo)#bar;
* lexer).
* ? or ~ followed by at least one appropriate_operator_suffix_chars.
*/
let x = ! !foo.bar;
let x = !foo.bar^;

let x = ?! !foo.bar;
let x = ?!foo.bar^;

let x = ! ?!foo.bar;
let x = !?!foo.bar;

let x = ~! !foo.bar;
let x = ~!foo.bar^;

let x = ! ~!foo.bar;
let x = !~!foo.bar;

let x = ~! ~!foo.bar;

Expand All @@ -77,33 +77,33 @@ let parensNeededAroundFirst = (!blah)#foo#bar;
let parensNeededAroundSecond = (!blah#foo)#bar;

let parensWithSpaceNeededAroundFirst =
(! !blah)#foo#bar;
(!(!blah))#foo#bar;

let parensWithSpaceNeededAroundSecond =
(! !blah#foo)#bar;
(!(!blah#foo))#bar;

let parensWithSpaceNeededAroundFirst =
(?!(+ blah))#foo#bar;

let parensWithSpaceNeededAroundSecond =
(?!(+ blah#foo))#bar;

let x = ! !foo.bar;
let x = !(!foo.bar);

let x = ! !foo#bar;
let x = !(!foo#bar);

/* Test precedence on access sugar */
let x = (!arr).(0);

let x = (!arr).(0);
let x = arr^.(0);

let x = (!str).[0];

let x = (!str).[0];
let x = str^.[0];

let x = (!arr).(0) = 1;
let x = arr^.(0) = 1;

let x = (!arr).(0) = 1;
let x = arr^.(0) = 1;

/* Comments */
/*Below is an empty comment*/
Expand Down Expand Up @@ -132,15 +132,15 @@ let logTapSuccess self =>
print_newline ()
};

(!data).field = true;
data^.field = true;

(!data).field1.field2 = true;
data^.field1.field2 = true;

(!data.field1).field2 = true;
data.field1^.field2 = true;

(!data).field1.field2 = true;
data^.field1.field2 = true;

(!data.field1).field2 = true;
data.field1^.field2 = true;

let loop appTime frameTime => {
if hasSetup.contents {
Expand Down Expand Up @@ -530,7 +530,7 @@ let functionReturnValueType
fun x => x + 1;

let curriedFormOne (i: int, s: string) =>
s ^ string_of_int i;
s ++ string_of_int i;

let curriedFormTwo (i: int, x: int) :(int, int) => (
i,
Expand Down
2 changes: 1 addition & 1 deletion formatTest/unit_tests/expected_output/fixme.re
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
let store_attributes proc_attributes => {
let should_write =
/* only overwrite defined procedures */ proc_attributes.ProcAttributes.is_defined ||
not (DB.file_exists attributes_file);
!DB.file_exists attributes_file;
should_write
};
2 changes: 1 addition & 1 deletion formatTest/unit_tests/expected_output/if.re
Original file line number Diff line number Diff line change
Expand Up @@ -194,5 +194,5 @@ let res = someExpression ? "true" : "false";

let pngSuffix =
pixRation > 1 ?
"@" ^ string_of_int pixRation ^ "x.png" :
"@" ++ string_of_int pixRation ++ "x.png" :
".png";
57 changes: 28 additions & 29 deletions formatTest/unit_tests/expected_output/infix.re
Original file line number Diff line number Diff line change
Expand Up @@ -108,29 +108,29 @@ let formatted =
((((a1 && a2) && b1) & b2) & y) &|| (x &|| z);

/* **...(right) is higher than *...(left) */
let parseTree = b1 *| b2 *| y *\*| x *\*| z;
let parseTree = b1 *| b2 *| (y **| (x **| z));

let minParens = b1 *| b2 *| y *\*| x *\*| z;
let minParens = b1 *| b2 *| (y **| (x **| z));

let formatted = b1 *| b2 *| y *\*| x *\*| z;
let formatted = b1 *| b2 *| (y **| (x **| z));

/* **...(right) is higher than *...(left) */
let parseTree =
b1 *| b2 *| y *\*| (x *\*| z *| a);
b1 *| b2 *| (y **| (x **| z *| a));

let minParens =
b1 *| b2 *| y *\*| (x *\*| z *| a);
b1 *| b2 *| (y **| (x **| z *| a));

let formatted =
b1 *| b2 *| y *\*| (x *\*| z *| a);
b1 *| b2 *| (y **| (x **| z *| a));

/* |...(left) is higher than ||(right) */
/* All parens should be removed when formatting n > 0 times */
let parseTree = b1 || b2 || y |\* x |\* z;
let parseTree = b1 || b2 || y |* x |* z;

let minParens = b1 || b2 || y |\* x |\* z;
let minParens = b1 || b2 || y |* x |* z;

let formatted = b1 || b2 || y |\* x |\* z;
let formatted = b1 || b2 || y |* x |* z;

/* Associativity effects how parenthesis should be dropped */
/* This one *shouldn't* expand into two consecutive infix + */
Expand Down Expand Up @@ -295,20 +295,19 @@ let equal = Pervasives.(==);

let starInfix_makeSureSpacesSurround = ( * );

let starInfix_makeSureSpacesSurround = ( *\*\* );
let starInfix_makeSureSpacesSurround = ( *** );

/* The following two should be equivalently parsed/printed. */
let includesACommentCloseInIdentifier = ( *\*\/ );
let includesACommentCloseInIdentifier = ( **\/ );

let includesACommentCloseInIdentifier = ( *\*\/ );
let includesACommentCloseInIdentifier = ( **\/ );

let shouldSimplifyAnythingExceptApplicationAndConstruction =
call "hi" ^
(
call "hi" ++ (
switch x {
| _ => "hi"
}
) ^ "yo";
) ++ "yo";

/* Add tests with IF/then mixed with infix/constructor application on left and right sides */

Expand All @@ -318,21 +317,21 @@ let shouldSimplifyAnythingExceptApplicationAndConstruction =
*/
let ( /\* ) a b => a + b;

let x = 12 /-\* 23 /-\* 12;
let x = 12 /-* 23 /-* 12;

let y = a /\* b;

let ( !=\* ) q r => q + r;
let ( !=* ) q r => q + r;

let res = q ( !=\* ) r;
let res = q ( !=* ) r;

let ( !=\/\* ) q r => q + r;
let ( !=/\* ) q r => q + r;

let res = q ( !=\/\* ) r;
let res = q ( !=/\* ) r;

let ( ~\* ) a => a + 1;
let ( ~* ) a => a + 1;

let res = ~\*10;
let res = ~*10;

let res = f - (- x);

Expand Down Expand Up @@ -920,9 +919,9 @@ let containingObject = {
* Unary plus/minus has lower precedence than prefix operators:
* And unary plus has same precedence as unary minus.
*/
let res = - !record;
let res = - record^;
/* Should be parsed as: */
let res = - !record;
let res = - record^;
/* Although that precedence ranking doesn't likely have any effect in that
* case. */

Expand All @@ -936,12 +935,12 @@ let containingObject = {
/**
* And this
*/
let res = !(- callThisFunc ());
let res = (- callThisFunc ())^;
/* Should be parsed (and should remain printed as: */
let res = !(- callThisFunc ());
let res = !x [@onApplication];
let res = !(x [@onX]);
let res = !(x [@onX]);
let res = (- callThisFunc ())^;
let res = x^ [@onApplication];
let res = (x [@onX])^;
let res = (x [@onX])^;
(something.contents = "newvalue")
[@shouldBeRenderedOnEntireSetField];
something.contents =
Expand Down
2 changes: 1 addition & 1 deletion formatTest/unit_tests/expected_output/syntax.re
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ let o: person = {name: "bob", age: 10};

let printPerson (p: person) => {
let q: person = p;
p.name ^ p.name
p.name ++ p.name
};

/* let dontParseMeBro x y:int = x = y;*/
Expand Down
2 changes: 1 addition & 1 deletion formatTest/unit_tests/expected_output/testUtils.re
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ let printSection s => {
print_string "\n---------------------\n"
};

let printLn s => print_string (s ^ "\n");
let printLn s => print_string (s ++ "\n");
Loading