{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE FlexibleInstances #-}
module Text.LambdaOptions.Keyword (
Keyword(..),
ToKeyword(..),
kw,
argText,
text,
) where
import Data.Data
import Data.String
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 = "" }
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 }