{-# LANGUAGE DeriveGeneric #-}
module Cabal.Optimization (
Optimization (..),
) where
import Control.Applicative (Alternative (..))
import GHC.Generics (Generic)
import qualified Distribution.Compat.CharParsing as C
import qualified Distribution.Parsec as C
import qualified Distribution.Pretty as C
import qualified Text.PrettyPrint as PP
data Optimization
= OptimizationOn
| OptimizationOff
| OptimizationLevel Int
deriving (Eq, Show, Generic)
instance C.Parsec Optimization where
parsec = boolean <|> numeric where
boolean = ite OptimizationOn OptimizationOff <$> C.parsec
numeric = OptimizationLevel <$> C.integral
ite t _ True = t
ite _ f False = f
instance C.Pretty Optimization where
pretty OptimizationOn = C.pretty True
pretty OptimizationOff = C.pretty False
pretty (OptimizationLevel l) = PP.int l