module Distribution.Parsec.Field (
Field (..),
fieldName,
fieldAnn,
fieldUniverse,
FieldLine (..),
SectionArg (..),
sectionArgAnn,
FieldName,
Name (..),
mkName,
getName,
nameAnn,
) where
import Prelude ()
import Distribution.Compat.Prelude
import Data.ByteString (ByteString)
import qualified Data.ByteString.Char8 as B
import qualified Data.Char as Char
data Field ann
= Field !(Name ann) [FieldLine ann]
| Section !(Name ann) [SectionArg ann] [Field ann]
deriving (Eq, Show, Functor)
fieldName :: Field ann -> Name ann
fieldName (Field n _ ) = n
fieldName (Section n _ _) = n
fieldAnn :: Field ann -> ann
fieldAnn = nameAnn . fieldName
fieldUniverse :: Field ann -> [Field ann]
fieldUniverse f@(Section _ _ fs) = f : concatMap fieldUniverse fs
fieldUniverse f@(Field _ _) = [f]
data FieldLine ann = FieldLine !ann !ByteString
deriving (Eq, Show, Functor)
data SectionArg ann
= SecArgName !ann !ByteString
| SecArgStr !ann !ByteString
| SecArgOther !ann !ByteString
deriving (Eq, Show, Functor)
sectionArgAnn :: SectionArg ann -> ann
sectionArgAnn (SecArgName ann _) = ann
sectionArgAnn (SecArgStr ann _) = ann
sectionArgAnn (SecArgOther ann _) = ann
type FieldName = ByteString
data Name ann = Name !ann !FieldName
deriving (Eq, Show, Functor)
mkName :: ann -> FieldName -> Name ann
mkName ann bs = Name ann (B.map Char.toLower bs)
getName :: Name ann -> FieldName
getName (Name _ bs) = bs
nameAnn :: Name ann -> ann
nameAnn (Name ann _) = ann