diff options
-rw-r--r-- | src/Language/Haskell/Stylish/Parse.hs | 23 | ||||
-rw-r--r-- | tests/Language/Haskell/Stylish/Parse/Tests.hs | 10 |
2 files changed, 32 insertions, 1 deletions
diff --git a/src/Language/Haskell/Stylish/Parse.hs b/src/Language/Haskell/Stylish/Parse.hs index 5162527..d9e0c9b 100644 --- a/src/Language/Haskell/Stylish/Parse.hs +++ b/src/Language/Haskell/Stylish/Parse.hs @@ -36,6 +36,27 @@ dropBom str = str -------------------------------------------------------------------------------- +-- | If +-- +-- > {-# LANGUAGE Haskell2010 #-} +-- +-- is specified, we need to add a number of extra extensions +addHaskell2010Extensions :: [H.Extension] -> [H.Extension] +addHaskell2010Extensions exts + -- For some reason Haskell2010 is not supported yet in haskell-src-exts + | H.UnknownExtension "Haskell2010" `elem` exts = exts ++ extra + | otherwise = exts + where + extra = + [ H.PatternGuards + , H.RelaxedPolyRec + , H.EmptyDataDecls + , H.ForeignFunctionInterface + , H.UnknownExtension "NoNPlusKPatterns" -- Not supported yet in HSE + ] + + +-------------------------------------------------------------------------------- -- | Abstraction over HSE's parsing parseModule :: Extensions -> Maybe FilePath -> String -> Either String Module parseModule extraExts mfp string = do @@ -43,7 +64,7 @@ parseModule extraExts mfp string = do let noBom = dropBom string extraExts' = map H.classifyExtension extraExts fileExts = fromMaybe [] $ H.readExtensions noBom - exts = fileExts ++ extraExts' + exts = addHaskell2010Extensions $ fileExts ++ extraExts' -- Parsing options... fp = fromMaybe "<unknown>" mfp diff --git a/tests/Language/Haskell/Stylish/Parse/Tests.hs b/tests/Language/Haskell/Stylish/Parse/Tests.hs index cd026fd..718c7f6 100644 --- a/tests/Language/Haskell/Stylish/Parse/Tests.hs +++ b/tests/Language/Haskell/Stylish/Parse/Tests.hs @@ -20,6 +20,7 @@ tests = testGroup "Language.Haskell.Stylish.Parse" [ testCase "UTF-8 Byte Order Mark" testBom , testCase "Extra extensions" testExtraExtensions , testCase "Multiline CPP" testMultilineCpp + , testCase "Haskell2010 extension" testHaskell2010 ] @@ -49,6 +50,15 @@ testMultilineCpp = assert $ isRight $ parseModule [] Nothing $ unlines -------------------------------------------------------------------------------- +testHaskell2010 :: Assertion +testHaskell2010 = assert $ isRight $ parseModule [] Nothing $ unlines + [ "{-# LANGUAGE Haskell2010 #-}" + , "module X where" + , "foo x | Just y <- x = y" + ] + + +-------------------------------------------------------------------------------- isRight :: Either a b -> Bool isRight (Right _) = True isRight _ = False |