{-# Language DeriveGeneric, DeriveTraversable, DeriveDataTypeable #-}
module Config.Value
( Section(..)
, Value(..)
, Atom(..)
, valueAnn
) where
import Data.Text (Text)
import Data.Data (Data, Typeable)
import Data.String (IsString(..))
import GHC.Generics (Generic, Generic1)
import Config.Number (Number)
data Section a = Section
{ sectionAnn :: a
, sectionName :: Text
, sectionValue :: Value a
}
deriving ( Eq, Read, Show, Typeable, Data
, Functor, Foldable, Traversable
, Generic, Generic1
)
newtype Atom = MkAtom { atomName :: Text }
deriving ( Eq, Ord, Show, Read, Typeable, Data
, Generic
)
instance IsString Atom where
fromString = MkAtom . fromString
data Value a
= Sections a [Section a]
| Number a Number
| Text a Text
| Atom a Atom
| List a [Value a]
deriving ( Eq, Read, Show, Typeable, Data
, Functor, Foldable, Traversable
, Generic, Generic1
)
valueAnn :: Value a -> a
valueAnn v =
case v of
Sections a _ -> a
Number a _ -> a
Text a _ -> a
Atom a _ -> a
List a _ -> a