{-# LANGUAGE CPP #-}
module HIndent.LanguageExtension.Conversion
( fromCabalExtension
, uniqueExtensions
, convertExtension
, strToExt
) where
import qualified GHC.LanguageExtensions as GLP
import HIndent.LanguageExtension.Types
import qualified Language.Haskell.Extension as Cabal
import qualified Language.Haskell.GhclibParserEx.GHC.Driver.Session as GLP
fromCabalExtension :: Cabal.Extension -> Maybe Extension
fromCabalExtension :: Extension -> Maybe Extension
fromCabalExtension (Cabal.EnableExtension KnownExtension
x) =
Extension -> Extension
EnableExtension (Extension -> Extension) -> Maybe Extension -> Maybe Extension
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> KnownExtension -> Maybe Extension
convertExtension KnownExtension
x
fromCabalExtension (Cabal.DisableExtension KnownExtension
x) =
Extension -> Extension
DisableExtension (Extension -> Extension) -> Maybe Extension -> Maybe Extension
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> KnownExtension -> Maybe Extension
convertExtension KnownExtension
x
fromCabalExtension Cabal.UnknownExtension {} = Maybe Extension
forall a. Maybe a
Nothing
uniqueExtensions :: [Extension] -> [GLP.Extension]
uniqueExtensions :: [Extension] -> [Extension]
uniqueExtensions [] = []
uniqueExtensions ((EnableExtension Extension
e):[Extension]
xs) = Extension
e Extension -> [Extension] -> [Extension]
forall a. a -> [a] -> [a]
: [Extension] -> [Extension]
uniqueExtensions [Extension]
xs
uniqueExtensions ((DisableExtension Extension
e):[Extension]
xs) =
[Extension] -> [Extension]
uniqueExtensions ([Extension] -> [Extension]) -> [Extension] -> [Extension]
forall a b. (a -> b) -> a -> b
$ (Extension -> Bool) -> [Extension] -> [Extension]
forall a. (a -> Bool) -> [a] -> [a]
filter (Extension -> Extension -> Bool
forall a. Eq a => a -> a -> Bool
/= Extension -> Extension
EnableExtension Extension
e) [Extension]
xs
convertExtension :: Cabal.KnownExtension -> Maybe GLP.Extension
convertExtension :: KnownExtension -> Maybe Extension
convertExtension = String -> Maybe Extension
GLP.readExtension (String -> Maybe Extension)
-> (KnownExtension -> String) -> KnownExtension -> Maybe Extension
forall b c a. (b -> c) -> (a -> b) -> a -> c
. KnownExtension -> String
forall a. Show a => a -> String
show
strToExt :: String -> Maybe Extension
strToExt :: String -> Maybe Extension
strToExt (Char
'N':Char
'o':String
s) = Extension -> Extension
DisableExtension (Extension -> Extension) -> Maybe Extension -> Maybe Extension
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> String -> Maybe Extension
GLP.readExtension String
s
strToExt String
s = Extension -> Extension
EnableExtension (Extension -> Extension) -> Maybe Extension -> Maybe Extension
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> String -> Maybe Extension
GLP.readExtension String
s