Support MultiWayIf.

This commit is contained in:
Robbie Gleichman 2019-01-08 21:29:51 -08:00
parent 34e054133f
commit b82e5f3b93
2 changed files with 15 additions and 1 deletions

View File

@ -297,6 +297,7 @@ hsExpToSimpExp x = simplifyExp $ case x of
Exts.EnumFromTo l e1 e2 -> desugarEnums l "enumFromTo" [e1, e2] Exts.EnumFromTo l e1 e2 -> desugarEnums l "enumFromTo" [e1, e2]
Exts.EnumFromThen l e1 e2 -> desugarEnums l "enumFromThen" [e1, e2] Exts.EnumFromThen l e1 e2 -> desugarEnums l "enumFromThen" [e1, e2]
Exts.EnumFromThenTo l e1 e2 e3 -> desugarEnums l "enumFromThenTo" [e1, e2, e3] Exts.EnumFromThenTo l e1 e2 e3 -> desugarEnums l "enumFromThenTo" [e1, e2, e3]
Exts.MultiIf l rhss -> SeGuard l (fmap guardedRhsToSelectorAndVal rhss)
_ -> error $ "Unsupported syntax in hsExpToSimpExp: " ++ show x _ -> error $ "Unsupported syntax in hsExpToSimpExp: " ++ show x
-- Parsing -- Parsing
@ -306,7 +307,8 @@ customParseMode = Exts.defaultParseMode
{Exts.extensions = {Exts.extensions =
[Exts.EnableExtension Exts.MultiParamTypeClasses, [Exts.EnableExtension Exts.MultiParamTypeClasses,
Exts.EnableExtension Exts.FlexibleContexts, Exts.EnableExtension Exts.FlexibleContexts,
Exts.EnableExtension Exts.TupleSections Exts.EnableExtension Exts.TupleSections,
Exts.EnableExtension Exts.MultiWayIf
] ]
} }

View File

@ -280,6 +280,17 @@ dataDeclTests = [
, "data Foo = Foo Int" , "data Foo = Foo Int"
] ]
multiWayIfTests :: [String]
multiWayIfTests = [
"y = if | x == 0 -> 1"
, "y = if\n\
\ | x == 0 -> 1\n\
\ | otherwise -> 2"
, "y = if\n\
\ | x == 0 -> if {| y > z -> 2; | pizza -> 3} \n\
\ | otherwise -> 2"
]
testDecls :: [String] testDecls :: [String]
testDecls = mconcat [ testDecls = mconcat [
simpleTests simpleTests
@ -298,6 +309,7 @@ testDecls = mconcat [
, otherTests , otherTests
, typeSigTests , typeSigTests
, dataDeclTests , dataDeclTests
, multiWayIfTests
] ]