Skip to content

Commit

Permalink
0.19 upgrade: replace Basics.curry
Browse files Browse the repository at this point in the history
  • Loading branch information
avh4 committed Apr 14, 2018
1 parent 8d16959 commit 674a580
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 0 deletions.
57 changes: 57 additions & 0 deletions src/ElmFormat/Upgrade_0_19.hs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ import qualified Reporting.Region as Region
transform :: Expr -> Expr
transform expr =
case RA.drop expr of
--
-- Basics.flip
--

VarExpr var | isBasics "flip" var ->
noRegion $ Lambda
[makeArg "f", makeArg "b", makeArg "a"] []
Expand Down Expand Up @@ -48,6 +52,59 @@ transform expr =
noRegion $ Parens
(Commented pre (noRegion $ App arg1 (arg3:arg2:argRest) multiline) [])

--
-- Basics.curry
--

VarExpr var | isBasics "curry" var ->
noRegion $ Lambda
[makeArg "f", makeArg "a", makeArg "b"] []
(noRegion $ App
(makeVarRef "f")
[([], noRegion $ AST.Expression.Tuple
[ Commented [] (makeVarRef "a") []
, Commented [] (makeVarRef "b") []
] False
)]
(FAJoinFirst JoinAll)
)
False

App (A _ (VarExpr var)) [(pre1, arg1)] _ | isBasics "curry" var ->
noRegion $ Lambda
[makeArg "a", makeArg "b"] pre1
(noRegion $ App arg1
[([], noRegion $ AST.Expression.Tuple
[ Commented [] (makeVarRef "a") []
, Commented [] (makeVarRef "b") []
] False
)]
(FAJoinFirst JoinAll)
)
False

App (A _ (VarExpr var)) [(pre1, arg1),(pre2, arg2)] _ | isBasics "curry" var ->
noRegion $ Lambda
[makeArg "b"] pre1
(noRegion $ App arg1
[([], noRegion $ AST.Expression.Tuple
[ Commented pre2 arg2 []
, Commented [] (makeVarRef "b") []
] False
)]
(FAJoinFirst JoinAll)
)
False

App (A _ (VarExpr var)) ((pre1, arg1):(pre2, arg2):(pre3, arg3):argRest) multiline | isBasics "curry" var ->
noRegion $ App arg1
((pre1, noRegion $ AST.Expression.Tuple
[ Commented pre2 arg2 []
, Commented pre3 arg3 []
] False
):argRest)
multiline

_ ->
expr

Expand Down
1 change: 1 addition & 0 deletions tests/run-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ checkUpgrade 0.19 Elm-0.19/CommaFunctionsBecomeLambdas.elm
checkUpgrade 0.19 Elm-0.19/RemoveBangOperator.elm
checkUpgrade 0.19 Elm-0.19/NewStringEscapeSyntax.elm
checkUpgrade 0.19 Elm-0.19/RemoveBasicsFlip.elm
checkUpgrade 0.19 Elm-0.19/RemoveBasicsCurry.elm

checkGood 0.18 Simple.elm
checkGood 0.18 AllSyntax/0.18/AllSyntax.elm
Expand Down
12 changes: 12 additions & 0 deletions tests/test-files/transform/Elm-0.19/RemoveBasicsCurry.elm
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
fullyApplied f = curry f "1" 2
fullyApplied_comments f = curry{-A-}f{-B-}"1"{-C-}2
partiallyApplied f = curry f "1"
partiallyApplied_comments f = curry{-A-}f{-B-}"1"
functionOnly f = curry f
functionOnly_comments f = curry{-A-}f
unapplied = curry
extraArgs f = curry f 1 2 3 4 5

qualified f = Basics.curry f "1" 2

nested f = curry f (curry f 1 2) 3
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
module Main exposing (..)


fullyApplied f =
f ( "1", 2 )


fullyApplied_comments f =
f {- A -} ( {- B -} "1", {- C -} 2 )


partiallyApplied f =
\b -> f ( "1", b )


partiallyApplied_comments f =
\b ->
{- A -}
f ( {- B -} "1", b )


functionOnly f =
\a b -> f ( a, b )


functionOnly_comments f =
\a b ->
{- A -}
f ( a, b )


unapplied =
\f a b -> f ( a, b )


extraArgs f =
f ( 1, 2 ) 3 4 5


qualified f =
f ( "1", 2 )


nested f =
f ( f ( 1, 2 ), 3 )

0 comments on commit 674a580

Please sign in to comment.