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

Improved BuckleScript method call syntax #941

Open
wants to merge 3 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
58 changes: 29 additions & 29 deletions formatTest/unit_tests/expected_output/bucklescript.re
Original file line number Diff line number Diff line change
@@ -1,71 +1,71 @@
bla#=10;
bla.= 10;

bla#=(Some 10);
bla.= (Some 10);

bla#=(someFunc (Some 10));
bla.= (someFunc (Some 10));

test##var#=(Some (-10));
test."var".= (Some (-10));

obj##.prop;

obj##.prod := exp;

preview##style##border#=(
Js.string "1px black dashed"
);
preview."style"."border".= (
Js.string "1px black dashed"
);

preview##(style##border)#=args somenum;
preview##(style."border")#=args somenum;

x##y##z#=(xxxx##yyyy##zzzz);
x."y"."z"##(xxxx."yyyy"."zzzz");

let result =
js_method_run1 (!react)#createElement foo;

add zz##yy xx##ww;
add zz."yy" xx."ww";

/* These should print the same */
let res = x##y + z##q; /* AST */
let res = x."y" + z."q"; /* AST */

let res = x##y + z##q; /* Minimum parens */
let res = x."y" + z."q"; /* Minimum parens */

/* These should print the same */
let res = y + z##q##a; /* AST */
let res = y + z."q"."a"; /* AST */

let res = y + z##q##a; /* Min parens */
let res = y + z."q"."a"; /* Min parens */

/* Make sure it's actually parsed as left precedence
* and that is maintained when printed */
let res = z##(q##a); /* AST */
let res = z##(q."a"); /* AST */

let res = z##(q##a); /* Min parens */
let res = z##(q."a"); /* Min parens */

/* These should print the same */
let res = !x##y; /* AST */
let res = !x."y"; /* AST */

let res = !x##y; /* Minimum parens */
let res = !x."y"; /* Minimum parens */

/* These should print the same */
let res = !z##q##a; /* AST */
let res = !z."q"."a"; /* AST */

let res = !z##q##a; /* Min parens */
let res = !z."q"."a"; /* Min parens */

/* These should print the same */
let res = ?!!x##y; /* AST */
let res = ?!!x."y"; /* AST */

let res = ?!!x##y; /* Minimum parens */
let res = ?!!x."y"; /* Minimum parens */

/* These should print the same */
let res = ?!!z##(q##a); /* AST */
let res = ?!!z##(q."a"); /* AST */

let res = ?!!z##(q##a); /* Min parens */
let res = ?!!z##(q."a"); /* Min parens */

res#=?!!z##q;
res.= ?!!z."q";

res#=?!!z##(q##a);
res.= ?!!z##(q."a");

let result = myFunction (x y##z) (a b#=c);
let result = myFunction (x y."z") (a b#=c);

(!x)##y##(b##c);
(!x)."y"##(b."c");

let a = {"key": 10};

Expand All @@ -76,7 +76,7 @@ let b = {
let c = {
"a": a,
"b": b,
"func": fun a => a##c#=(func 10)
"func": fun a => a."c".= (func 10)
};

let d = {
Expand Down
55 changes: 28 additions & 27 deletions formatTest/unit_tests/input/bucklescript.re
Original file line number Diff line number Diff line change
@@ -1,66 +1,67 @@
bla#=10;
bla.=10;

bla#=(Some 10);
bla.=(Some 10);

bla#=(someFunc (Some 10));
bla.=(someFunc (Some 10));

test##var#=(Some (-10));
test."var".=(Some (-10));

obj##.prop;

obj##.prod := exp;

preview##style##border#=(Js.string "1px black dashed");
preview."style"."border".=(Js.string "1px black dashed");

(preview##(style##border)#=args) somenum;
(preview##(style##border)#= args) somenum;

(x##y)##z#=((xxxx##yyyy)##zzzz);
(x."y")."z"#=((xxxx."yyyy")."zzzz");

let result = js_method_run1 (!react)#createElement foo;

add zz##yy xx##ww;
add zz."yy" xx."ww";

/* These should print the same */
let res = ((x##y) + (z##q)); /* AST */
let res = x##y + z##q; /* Minimum parens */
let res = ((x."y") + (z."q")); /* AST */
let res = x."y" + z."q"; /* Minimum parens */

/* These should print the same */
let res = (y + (z##q)##a); /* AST */
let res = y + z##q##a; /* Min parens */
let res = (y + (z."q")."a"); /* AST */
let res = y + z."q"."a"; /* Min parens */

/* Make sure it's actually parsed as left precedence
* and that is maintained when printed */
let res = (z##(q##a)); /* AST */
let res = z##(q##a); /* Min parens */
let res = (z##(q."a")); /* AST */
let res = z##(q."a"); /* Min parens */

/* These should print the same */
let res = (! (x##y)); /* AST */
let res = !x##y; /* Minimum parens */
let res = (! (x."y")); /* AST */
let res = !x."y"; /* Minimum parens */

/* These should print the same */
let res = (!(z##q)##a); /* AST */
let res = !z##q##a; /* Min parens */
let res = (!(z."q")."a"); /* AST */
let res = !z."q"."a"; /* Min parens */

/* These should print the same */
let res = (?!! (x##y)); /* AST */
let res = ?!!x##y; /* Minimum parens */
let res = (?!! (x."y")); /* AST */
let res = ?!!x."y"; /* Minimum parens */

/* These should print the same */
let res = (?!!z##(q##a)); /* AST */
let res = ?!!z##(q##a); /* Min parens */
let res = (?!!z##(q."a")); /* AST */
let res = ?!!z##(q."a"); /* Min parens */

res #= ?!!z ## q;
res #= ?!!z##(q##a);
res #= (?!!z ."q");

let result = myFunction (x y ## z) (a b #= c);
res #= ?!!z##(q."a");

(!x)##y##(b##c);
let result = myFunction (x y ."z") (a b #= c);

(!x)."y"##(b."c");

let a = {"key": 10};

let b = {"nested": {"objs": {"are": {"nice": "<3"}}}};

let c = {"a": a, "b": b, "func": fun a => a##c#=(func 10)};
let c = {"a": a, "b": b, "func": fun a => a."c"#=(func 10)};

let d = {"a": a2, "b": b , "func": fun a => {"a": (fun arg1 arg2 => arg1 + arg2)}};

Expand Down
1 change: 1 addition & 0 deletions src/reason_lexer.mll
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,7 @@ rule token = parse
| "=>" { EQUALGREATER }
| "#" { SHARP }
| "." { DOT }
| ".=" { DOTEQUAL }
| ".." { DOTDOT }
| "..."{ DOTDOTDOT }
| ":" { COLON }
Expand Down
Loading