Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tag: v0.3.2
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 51 lines (39 sloc) 1.308 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
module Portage.Use (
  -- * main structures
  UseFlag(..),
  Use,
  dispUses,
  -- * helpers
  mkUse,
  mkNotUse,
  mkQUse
  ) where

import qualified Text.PrettyPrint as Disp
import Text.PrettyPrint ((<>))
import Distribution.Text ( Text(..) )

-- | 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 = UseFlag

mkQUse :: Use -> UseFlag
mkQUse = Q . UseFlag


instance Text UseFlag where
  disp = showModificator

showModificator :: UseFlag -> Disp.Doc
showModificator (UseFlag u) = Disp.text u
showModificator (X u) = Disp.char '!' <> disp u
showModificator (Q u) = disp u <> Disp.char '?'
showModificator (E u) = disp u <> Disp.char '='
showModificator (N u) = Disp.char '-' <> disp u

dispUses :: [UseFlag] -> Disp.Doc
dispUses [] = Disp.empty
dispUses us = Disp.brackets $ Disp.hcat $ (Disp.punctuate (Disp.text ", ")) $ map disp us

type Use = String

Something went wrong with that request. Please try again.