Skip to content

Commit

Permalink
Implement correct printing for fast pipe sugar (#2087)
Browse files Browse the repository at this point in the history
* Implement correct printing for fast pipe sugar
+ make sure uncurried expressions are formatted correctly
under fast pipe sugar

* remove unused code

* Fix unit sugar + add test

* improve naming of anonymous function arg which formats the pipe segments
  • Loading branch information
IwanKaramazow authored and chenglou committed Jul 28, 2018
1 parent 5ed38a9 commit e233916
Show file tree
Hide file tree
Showing 7 changed files with 231 additions and 66 deletions.
34 changes: 30 additions & 4 deletions formatTest/unit_tests/expected_output/fastPipe.re
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,32 @@ foo->f->g->h;

bar->f->g->h;

foo(g)->f(a, b)->g(c, d);

foo->f();

compilation
->Plugin.buildAssets
->Js.Json.stringify
->Node.Fs.writeFileAsUtf8Sync(
_,
path,
);
->Node.Fs.writeFileAsUtf8Sync(_, path);

foo
->someLongIdentifier
->otherLongIdentifierWithArgs(a, b, c)
->longIdentWithVeryLongArgs(
aaaaaaaaaaaaaaaaaaaaa,
bbbbbbbbbbbbbbbb,
ccccccccccccc,
);

/* with comments */
compilation
/* first */
->Plugin.buildAssets /* first trail */
/* second */
->Js.Json.stringify /* second trail */
/* last */
->Node.Fs.writeFileAsUtf8Sync(_, path); /* last trail */

foo->bar->baz >>= monadicFunction |> bind;

Expand Down Expand Up @@ -77,3 +96,10 @@ location##streets.foo[1];
(event->target^)##value;

event->target^ #= value;

foo->f(. a, b);
foo->f(. a, b)->g(. c, d);
foo->([@attr] f(. a, b))->([@attr2] f(. a, b));
foo->f(.);
foo->f(.)->g(.);
foo->([@attr] f(.))->([@attr] g(.));
25 changes: 25 additions & 0 deletions formatTest/unit_tests/input/fastPipe.re
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,29 @@ foo |. f |. g |. h;

bar->f->g->h;

foo(g)->f(a, b)->g(c, d);

foo->f();

compilation
->Plugin.buildAssets
->Js.Json.stringify
->Node.Fs.writeFileAsUtf8Sync(_, path);

foo
->someLongIdentifier
->otherLongIdentifierWithArgs(a, b, c)
->longIdentWithVeryLongArgs(aaaaaaaaaaaaaaaaaaaaa, bbbbbbbbbbbbbbbb, ccccccccccccc);

/* with comments */
compilation
/* first */
->Plugin.buildAssets /* first trail */
/* second */
->Js.Json.stringify /* second trail */
/* last */
->Node.Fs.writeFileAsUtf8Sync(_, path); /* last trail */

foo->bar->baz >>= monadicFunction |> bind;

compilation
Expand Down Expand Up @@ -78,3 +96,10 @@ event->target##(value(foo));
(event->target^)##value;

event->target^ #= value;

foo->f(. a, b);
foo->f(. a, b)->g(. c, d);
foo->([@attr] f(. a, b))->([@attr2] f(. a, b));
foo->f(.);
foo->f(.)->g(.);
foo->([@attr] f(.))->([@attr] g(.));
1 change: 0 additions & 1 deletion src/reason-parser/jbuild
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@
(wrapped false)
(modules
(lexer_warning
reason_ast
reason_syntax_util
reason_comment
reason_layout
Expand Down
16 changes: 0 additions & 16 deletions src/reason-parser/reason_ast.ml

This file was deleted.

1 change: 0 additions & 1 deletion src/reason-parser/reason_ast.mli

This file was deleted.

8 changes: 8 additions & 0 deletions src/reason-parser/reason_heuristics.ml
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,11 @@ let isUnderscoreIdent expr =
match Ast_404.Parsetree.(expr.pexp_desc) with
| Pexp_ident ({txt = Lident "_"}) -> true
| _ -> false

let isFastPipe e = match Ast_404.Parsetree.(e.pexp_desc) with
| Pexp_ident({txt = Longident.Lident("|.")}) -> true
| Pexp_apply(
{pexp_desc = Pexp_ident({txt = Longident.Lident("|.")})},
_
) -> true
| _ -> false
Loading

0 comments on commit e233916

Please sign in to comment.