{-# OPTIONS_HADDOCK hide #-}
-----------------------------------------------------------------------------
-- |
-- Module      :  Language.Haskell.Exts.ExtScheme
-- Copyright   :  (c) Niklas Broberg 2009
-- License     :  BSD-style (see the file LICENSE.txt)
--
-- Maintainer  :  Niklas Broberg, d00nibro@chalmers.se
-- Stability   :  stable
-- Portability :  portable
--
-- Internal scheme for handling extensions in a
-- convenient fashion.
--
-----------------------------------------------------------------------------
module Language.Haskell.Exts.ExtScheme where

import Language.Haskell.Exts.Extension

data ExtScheme = Any [KnownExtension] | All [KnownExtension]
  deriving (ExtScheme -> ExtScheme -> Bool
(ExtScheme -> ExtScheme -> Bool)
-> (ExtScheme -> ExtScheme -> Bool) -> Eq ExtScheme
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ExtScheme -> ExtScheme -> Bool
== :: ExtScheme -> ExtScheme -> Bool
$c/= :: ExtScheme -> ExtScheme -> Bool
/= :: ExtScheme -> ExtScheme -> Bool
Eq,Int -> ExtScheme -> ShowS
[ExtScheme] -> ShowS
ExtScheme -> String
(Int -> ExtScheme -> ShowS)
-> (ExtScheme -> String)
-> ([ExtScheme] -> ShowS)
-> Show ExtScheme
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ExtScheme -> ShowS
showsPrec :: Int -> ExtScheme -> ShowS
$cshow :: ExtScheme -> String
show :: ExtScheme -> String
$cshowList :: [ExtScheme] -> ShowS
showList :: [ExtScheme] -> ShowS
Show)

type MExtScheme = Maybe ExtScheme

class Enabled a where
  isEnabled :: a -> [KnownExtension] -> Bool

instance Enabled KnownExtension where
  isEnabled :: KnownExtension -> [KnownExtension] -> Bool
isEnabled = KnownExtension -> [KnownExtension] -> Bool
forall a. Eq a => a -> [a] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
elem

instance Enabled ExtScheme where
  isEnabled :: ExtScheme -> [KnownExtension] -> Bool
isEnabled (Any [KnownExtension]
exts) [KnownExtension]
enabled = (KnownExtension -> Bool) -> [KnownExtension] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any (KnownExtension -> [KnownExtension] -> Bool
forall a. Eq a => a -> [a] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [KnownExtension]
enabled) [KnownExtension]
exts
  isEnabled (All [KnownExtension]
exts) [KnownExtension]
enabled = (KnownExtension -> Bool) -> [KnownExtension] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all (KnownExtension -> [KnownExtension] -> Bool
forall a. Eq a => a -> [a] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [KnownExtension]
enabled) [KnownExtension]
exts

instance Enabled a => Enabled (Maybe a) where
  isEnabled :: Maybe a -> [KnownExtension] -> Bool
isEnabled Maybe a
Nothing  = Bool -> [KnownExtension] -> Bool
forall a b. a -> b -> a
const Bool
True
  isEnabled (Just a
a) = a -> [KnownExtension] -> Bool
forall a. Enabled a => a -> [KnownExtension] -> Bool
isEnabled a
a