{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE Safe #-}
module Text.LambdaOptions.Keyword (
Keyword(..),
ToKeyword(..),
kw,
argText,
text,
) where
import Data.Data
( Data, Typeable )
import Data.String
( IsString(fromString) )
data Keyword
= Keyword
{ kwNames :: [String]
, kwArgText :: String
, kwText :: String
}
deriving (Typeable, Data, Show, Eq, Ord)
instance IsString Keyword where
fromString name = kw [name]
class ToKeyword a where
toKeyword :: a -> Keyword
instance ToKeyword Keyword where
toKeyword = id
instance ToKeyword String where
toKeyword name = toKeyword [name]
instance ToKeyword [String] where
toKeyword names = Keyword
{ kwNames = names
, kwArgText = ""
, kwText = ""
}
instance ToKeyword () where
toKeyword () = toKeyword ([] :: [String])
kw :: (ToKeyword a) => a -> Keyword
kw = toKeyword
argText :: Keyword -> String -> Keyword
argText k s = k
{ kwArgText = s
}
text :: Keyword -> String -> Keyword
text k s = k
{ kwText = s
}