Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

61 lines (49 sloc) 1.745 kb
module Portage.Use (
-- * main structures
UseFlag(..),
Use(..),
dispUses,
-- * helpers
mkUse,
mkNotUse,
mkQUse
) where
import qualified Text.PrettyPrint as Disp
import Text.PrettyPrint ((<>))
import qualified Distribution.Text as DT
-- | Use variable modificator
data UseFlag = UseFlag Use -- ^ no modificator
| E UseFlag -- ^ = modificator (Equiv mark)
| Q UseFlag -- ^ ? modificator (Question mark)
| X UseFlag -- ^ ! modificator (eXclamation mark)
| N UseFlag -- ^ - modificator
deriving (Eq,Show,Ord,Read)
mkUse :: Use -> UseFlag
mkUse = UseFlag
mkNotUse :: Use -> UseFlag
mkNotUse = N . UseFlag
mkQUse :: Use -> UseFlag
mkQUse = Q . UseFlag
instance DT.Text UseFlag where
disp = showModificator
parse = error "instance DT.Text UseFlag: not implemented"
showModificator :: UseFlag -> Disp.Doc
showModificator (UseFlag u) = DT.disp u
showModificator (X u) = Disp.char '!' <> DT.disp u
showModificator (Q u) = DT.disp u <> Disp.char '?'
showModificator (E u) = DT.disp u <> Disp.char '='
showModificator (N u) = Disp.char '-' <> DT.disp u
dispUses :: [UseFlag] -> Disp.Doc
dispUses [] = Disp.empty
dispUses us = Disp.brackets $ Disp.hcat $ (Disp.punctuate (Disp.text ", ")) $ map DT.disp us
newtype Use = Use String
deriving (Eq, Read, Show)
instance Ord Use where
compare (Use a) (Use b) = case (a,b) of
("test", "test") -> EQ
("test", _) -> LT
(_, "test") -> GT
(_, _) -> a `compare` b
instance DT.Text Use where
disp (Use u) = Disp.text u
parse = error "instance DT.Text Use: not implemented"
Jump to Line
Something went wrong with that request. Please try again.